mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-03-10 08:31:23 +00:00
Fix 3.1 generation for composed schema's with type object (#18002)
This commit is contained in:
@@ -7526,7 +7526,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -794,6 +794,35 @@ public class JavaClientCodegenTest {
|
||||
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();
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user