forked from loafle/openapi-generator-original
make title
available to templates for ref properties (#17881)
Even though `title` is technically for the title of the API itself, it's possible to set it for properties as well. Right now, the `title` property is available in templates for regular properties, but for ref-properties it gets lost right here. This seemed rather surprising to me, so I think it's better to fix.
This commit is contained in:
parent
28b75377b5
commit
6350d1d191
@ -4235,6 +4235,9 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
if (original.getMinimum() != null) {
|
||||
property.setMinimum(String.valueOf(original.getMinimum().doubleValue()));
|
||||
}
|
||||
if (original.getTitle() != null) {
|
||||
property.setTitle(original.getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
// set the default value
|
||||
|
@ -1916,6 +1916,19 @@ public class DefaultCodegenTest {
|
||||
Assert.assertFalse(codegen.fromProperty("customerCode", (Schema) requestProperties.get("customerCode")).deprecated);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTitleProperty() {
|
||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/property-title.yaml");
|
||||
new InlineModelResolver().flatten(openAPI);
|
||||
final DefaultCodegen codegen = new DefaultCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
|
||||
final Map testProperties = Collections.unmodifiableMap(openAPI.getComponents().getSchemas().get("ModelWithTitledProperties").getProperties());
|
||||
|
||||
Assert.assertEquals("Simple-Property-Title", codegen.fromProperty("simpleProperty", (Schema) testProperties.get("simpleProperty")).title);
|
||||
Assert.assertEquals("Ref-Property-Title", codegen.fromProperty("refProperty", (Schema) testProperties.get("refProperty")).title);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeprecatedRef() {
|
||||
final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/model-deprecated.yaml");
|
||||
|
@ -0,0 +1,29 @@
|
||||
openapi: 3.0.1
|
||||
paths:
|
||||
/foo:
|
||||
get:
|
||||
responses:
|
||||
'200':
|
||||
description: ok
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/test'
|
||||
info:
|
||||
title: Title on Properties
|
||||
version: "1.0"
|
||||
components:
|
||||
schemas:
|
||||
ModelWithTitledProperties:
|
||||
properties:
|
||||
simpleProperty:
|
||||
type: string
|
||||
title: Simple-Property-Title
|
||||
refProperty:
|
||||
type: string
|
||||
title: Ref-Property-Title
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/RefObject'
|
||||
type: object
|
||||
RefObject:
|
||||
type: string
|
Loading…
x
Reference in New Issue
Block a user