forked from loafle/openapi-generator-original
Fix: Inline models can't be generated (#1768)
* Add a test case * Fix that the inline models couldn't be flatten when "components" doesn't exist * Rename yaml file * Rename method name
This commit is contained in:
parent
f96e64bd9e
commit
354db2f3e6
@ -17,6 +17,7 @@
|
||||
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import io.swagger.v3.oas.models.Components;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
@ -49,7 +50,7 @@ public class InlineModelResolver {
|
||||
this.openapi = openapi;
|
||||
|
||||
if (openapi.getComponents() == null) {
|
||||
return; // There's nothing here
|
||||
openapi.setComponents(new Components());
|
||||
}
|
||||
|
||||
if (openapi.getComponents().getSchemas() == null) {
|
||||
|
@ -24,7 +24,9 @@ import io.swagger.v3.oas.models.parameters.RequestBody;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponses;
|
||||
import io.swagger.v3.parser.core.models.ParseOptions;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -274,6 +276,16 @@ public class InlineModelResolverTest {
|
||||
assertTrue(model.getProperties().get("name") instanceof StringSchema);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveInlineRequestBodyWhenNoComponents() {
|
||||
OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/inline_request_body_no_components.yaml", null, new ParseOptions()).getOpenAPI();
|
||||
new InlineModelResolver().flatten(openAPI);
|
||||
|
||||
assertNotNull(openAPI.getComponents());
|
||||
assertNotNull(openAPI.getComponents().getRequestBodies());
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void resolveInlineArraySchemaWithTitle() {
|
||||
OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/inline_model_resolver.yaml", null, new ParseOptions()).getOpenAPI();
|
||||
|
@ -0,0 +1,24 @@
|
||||
openapi: 3.0.1
|
||||
info:
|
||||
version: 1.0.0
|
||||
title: Example
|
||||
license:
|
||||
name: MIT
|
||||
servers:
|
||||
- url: http://api.example.xyz/v1
|
||||
paths:
|
||||
/test1:
|
||||
post:
|
||||
requestBody:
|
||||
description: test
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
operationId: test1
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
Loading…
x
Reference in New Issue
Block a user