-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Bugfix/3248 #3857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix/3248 #3857
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -525,31 +525,6 @@ public static boolean isEmailSchema(Schema schema) { | |
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Check to see if the schema is a model with at least one properties | ||
| * | ||
| * @param schema potentially containing a '$ref' | ||
| * @return true if it's a model with at least one properties | ||
| */ | ||
| public static boolean isModel(Schema schema) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing a public helper is a breaking change (these are used by programmatic consumers, and this would therefore need to be deprecated before removal). |
||
| if (schema == null) { | ||
| LOGGER.error("Schema cannot be null in isModel check"); | ||
| return false; | ||
| } | ||
|
|
||
| // has at least one property | ||
| if (schema.getProperties() != null && !schema.getProperties().isEmpty()) { | ||
| return true; | ||
| } | ||
|
|
||
| // composed schema is a model | ||
| if (schema instanceof ComposedSchema) { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Check to see if the schema is a free form object | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| {{#isQueryParam}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"{{/allowableValues}}{{^isContainer}}{{#defaultValue}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}) {{#useBeanValidation}}@Valid{{/useBeanValidation}}{{^isModel}} @RequestParam(value = "{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{^isContainer}}{{#defaultValue}}, defaultValue={{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}){{/isModel}} {{>optionalDataType}} {{paramName}}{{/isQueryParam}} | ||
| {{#isQueryParam}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"{{/allowableValues}}{{^isContainer}}{{#defaultValue}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}) {{#useBeanValidation}}@Valid{{/useBeanValidation}}{{#isPrimitiveType}} @RequestParam(value = "{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{^isContainer}}{{#defaultValue}}, defaultValue={{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}){{/isPrimitiveType}} {{>optionalDataType}} {{paramName}}{{/isQueryParam}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -836,21 +836,6 @@ private Map<String, Object> codegenModelWithXEnumVarName() { | |
| return objs; | ||
| } | ||
|
|
||
| @Test | ||
| public void objectQueryParamIdentifyAsObject() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NOTE: Removing this test/functionality would be considered a breaking change and would need to be documented as a regression. |
||
| final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/objectQueryParam.yaml"); | ||
| new InlineModelResolver().flatten(openAPI); | ||
| final DefaultCodegen codegen = new DefaultCodegen(); | ||
| codegen.setOpenAPI(openAPI); | ||
|
|
||
| Set<String> imports = new HashSet<>(); | ||
| CodegenParameter parameter = codegen.fromParameter(openAPI.getPaths().get("/pony").getGet().getParameters().get(0), imports); | ||
|
|
||
| Assert.assertEquals(parameter.dataType, "PageQuery"); | ||
| Assert.assertEquals(imports.size(), 1); | ||
| Assert.assertEquals(imports.iterator().next(), "PageQuery"); | ||
| } | ||
|
|
||
| @Test | ||
| public void mapParamImportInnerObject() { | ||
| final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/mapArgs.yaml"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| openapi: 3.0.0 | ||
| servers: | ||
| - url: 'localhost:8080' | ||
| info: | ||
| version: 1.0.0 | ||
| title: OpenAPI Petstore | ||
| license: | ||
| name: Apache-2.0 | ||
| url: 'http://www.apache.org/licenses/LICENSE-2.0.html' | ||
| paths: | ||
| /monkeys: | ||
| get: | ||
| operationId: getMonkeys | ||
| parameters: | ||
| - $ref: '#/components/parameters/refDate' | ||
| /elephants: | ||
| get: | ||
| operationId: getElephants | ||
| parameters: | ||
| - in: query | ||
| name: someDate | ||
| required: true | ||
| schema: | ||
| type: string | ||
| format: date | ||
| /girafes: | ||
| get: | ||
| operationId: getGirafes | ||
| parameters: | ||
| - $ref: '#/components/parameters/refStatus' | ||
| /zebras: | ||
| get: | ||
| operationId: getZebras | ||
| parameters: | ||
| - in: query | ||
| name: status | ||
| required: true | ||
| schema: | ||
| type: integer | ||
| enum: [0,1] | ||
| default: 0 | ||
| /bears: | ||
| get: | ||
| operationId: getBears | ||
| parameters: | ||
| - $ref: '#/components/parameters/refCondition' | ||
| /camels: | ||
| get: | ||
| operationId: getCamels | ||
| parameters: | ||
| - in: query | ||
| name: condition | ||
| required: true | ||
| schema: | ||
| type: string | ||
| enum: | ||
| - sleeping | ||
| - awake | ||
| /pandas: | ||
| get: | ||
| operationId: getPandas | ||
| parameters: | ||
| - $ref: '#/components/parameters/refName' | ||
| /crocodiles: | ||
| get: | ||
| operationId: getCrocodiles | ||
| parameters: | ||
| - in: query | ||
| name: name | ||
| required: true | ||
| schema: | ||
| type: string | ||
| /polarBears: | ||
| get: | ||
| operationId: getPolarBears | ||
| parameters: | ||
| - $ref: '#/components/parameters/refAge' | ||
| /birds: | ||
| get: | ||
| operationId: getBirds | ||
| parameters: | ||
| - in: query | ||
| name: age | ||
| required: true | ||
| schema: | ||
| type: integer | ||
| components: | ||
| parameters: | ||
| refDate: | ||
| in: query | ||
| name: refDate | ||
| required: true | ||
| schema: | ||
| type: string | ||
| format: date | ||
| refStatus: | ||
| in: query | ||
| name: refStatus | ||
| required: true | ||
| schema: | ||
| type: integer | ||
| enum: [0,1] | ||
| default: 0 | ||
| refCondition: | ||
| in: query | ||
| name: refCondition | ||
| schema: | ||
| type: string | ||
| enum: | ||
| - sleeping | ||
| - awake | ||
| refName: | ||
| in: query | ||
| name: refName | ||
| schema: | ||
| type: string | ||
| refAge: | ||
| in: query | ||
| name: refAge | ||
| schema: | ||
| type: integer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're changing the template to not use
isModel, we should keep this as the change affects all generators. See my resolution in #3855, which setsisModelas expected (after the naive attempt done insetNonArrayMapProperty.