Skip to content

Commit

Permalink
Fix 3.1 generation for composed schema's with type object (#18002)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-getsov committed Mar 1, 2024
1 parent d4e1050 commit d3ebb0a
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7526,7 +7526,7 @@ protected void updateRequestBodyForObject(CodegenParameter codegenParameter, Sch
}
// set nullable
setParameterNullable(codegenParameter, codegenProperty);
} else if (ModelUtils.isObjectSchema(schema)) {
} else if (ModelUtils.isObjectSchema(schema) || ModelUtils.isComposedSchema(schema)) {
// object type schema or composed schema with properties defined
this.addBodyModelSchema(codegenParameter, name, schema, imports, bodyParameterName, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,35 @@ public void testAuthorizationScopeValues_Issue6733() throws IOException {
files.forEach(File::deleteOnExit);
}

@Test
public void testTypedAndNonTypedComposedSchemaGeneration_3_1() throws IOException {
File output = Files.createTempDirectory("test").toFile();
output.deleteOnExit();

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("java")
.setLibrary(JavaClientCodegen.RESTEASY)
.setValidateSpec(false)
.setInputSpec("src/test/resources/3_1/composed-schemas-with-and-without-type.yaml")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));

final ClientOptInput clientOptInput = configurator.toClientOptInput();

DefaultGenerator generator = new DefaultGenerator();
generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true");
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false");
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false");
generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "true");
generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false");
generator.setGenerateMetadata(false);
List<File> files = generator.opts(clientOptInput).generate();

validateJavaSourceFiles(files);

Assert.assertEquals(files.size(), 9);
files.forEach(File::deleteOnExit);
}

@Test
public void testMultiPartSpecifiesFileName_Issue17367() throws IOException {
File output = Files.createTempDirectory("test").toFile();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
openapi: 3.1.0
info:
version: 1.0.0
title: Example
license:
name: MIT
servers:
- url: http://api.example.xyz/v1
paths:
/pets:
patch:
requestBody:
content:
application/json:
schema:
type: object
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
- description: Any kind of pet
discriminator:
propertyName: pet_type
responses:
'200':
description: Updated
/pets-filtered:
patch:
requestBody:
content:
application/json:
schema:
anyOf:
- $ref: '#/components/schemas/PetByAge'
- $ref: '#/components/schemas/PetByType'
- description: Any kind of filter
responses:
'200':
description: Updated
components:
schemas:
Pet:
type: object
required:
- pet_type
Dog:
allOf:
- description: Dog information
- $ref: '#/components/schemas/Pet'
- type: object
properties:
bark:
type: boolean
breed:
type: string
enum: [Dingo, Husky, Retriever, Shepherd]
Cat:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
hunts:
type: boolean
age:
type: integer
PetByAge:
type: object
properties:
age:
type: integer
nickname:
type: string
required:
- age
PetByType:
type: object
properties:
pet_type:
type: string
enum: [Cat, Dog]
hunts:
type: boolean
required:
- pet_type

0 comments on commit d3ebb0a

Please sign in to comment.