Skip to content
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

[JAVA] Fix 3.1 generation for composed schema's with object type #18002

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading