forked from loafle/openapi-generator-original
[Core] Minor enhancements (#2863)
* fix getcontenttype, better working for skipFormModel * add tests for allof
This commit is contained in:
parent
98afbe062b
commit
9323cad06b
@ -2563,8 +2563,9 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
CodegenParameter bodyParam = null;
|
||||
RequestBody requestBody = operation.getRequestBody();
|
||||
if (requestBody != null) {
|
||||
if (getContentType(requestBody).toLowerCase(Locale.ROOT).startsWith("application/x-www-form-urlencoded") ||
|
||||
getContentType(requestBody).toLowerCase(Locale.ROOT).startsWith("multipart/form-data")) {
|
||||
if (getContentType(requestBody) != null &&
|
||||
(getContentType(requestBody).toLowerCase(Locale.ROOT).startsWith("application/x-www-form-urlencoded") ||
|
||||
getContentType(requestBody).toLowerCase(Locale.ROOT).startsWith("multipart/form-data"))) {
|
||||
// process form parameters
|
||||
formParams = fromRequestBodyToFormParameters(requestBody, imports);
|
||||
for (CodegenParameter cp : formParams) {
|
||||
@ -4256,8 +4257,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
protected String getContentType(RequestBody requestBody) {
|
||||
if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) {
|
||||
LOGGER.warn("Cannot determine the content type. Default to UNKNOWN_CONTENT_TYPE.");
|
||||
return "UNKNOWN_CONTENT_TYPE";
|
||||
LOGGER.debug("Cannot determine the content type. Returning null.");
|
||||
return null;
|
||||
}
|
||||
return new ArrayList<>(requestBody.getContent().keySet()).get(0);
|
||||
}
|
||||
|
@ -434,9 +434,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
if (unusedModels.contains(name)) {
|
||||
if (Boolean.FALSE.equals(skipFormModel)) {
|
||||
// if skipFormModel sets to true, still generate the model and log the result
|
||||
LOGGER.info("Model " + name + " (marked as unused due to form parameters) is generated due to skipFormModel=false (default)");
|
||||
LOGGER.info("Model " + name + " (marked as unused due to form parameters) is generated due to the system property skipFormModel=false (default)");
|
||||
} else {
|
||||
LOGGER.info("Model " + name + " not generated since it's marked as unused (due to form parameters) and skipFormModel set to true");
|
||||
LOGGER.info("Model " + name + " not generated since it's marked as unused (due to form parameters) and skipFormModel (system property) set to true");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -521,6 +521,47 @@ public class RubyClientCodegenTest {
|
||||
Assert.assertEquals(cp1.name, "person_required");
|
||||
}
|
||||
|
||||
@Test(description = "test allOf composition")
|
||||
public void allOfCompositionTest() {
|
||||
final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/allOf_composition.yaml");
|
||||
final RubyClientCodegen codegen = new RubyClientCodegen();
|
||||
codegen.setModuleName("OnlinePetstore");
|
||||
|
||||
final Schema schema = openAPI.getComponents().getSchemas().get("SuperMan");
|
||||
codegen.setOpenAPI(openAPI);
|
||||
CodegenModel superMan = codegen.fromModel("SuperMan", schema);
|
||||
Assert.assertNotNull(superMan);
|
||||
|
||||
// to test all properties
|
||||
Assert.assertEquals(superMan.getVars().size(), 6);
|
||||
|
||||
CodegenProperty cp0 = superMan.getVars().get(0);
|
||||
Assert.assertEquals(cp0.name, "id");
|
||||
Assert.assertTrue(cp0.required);
|
||||
|
||||
CodegenProperty cp1 = superMan.getVars().get(1);
|
||||
Assert.assertEquals(cp1.name, "name");
|
||||
Assert.assertFalse(cp1.required);
|
||||
|
||||
CodegenProperty cp2 = superMan.getVars().get(2);
|
||||
Assert.assertEquals(cp2.name, "reward");
|
||||
Assert.assertFalse(cp2.required);
|
||||
|
||||
CodegenProperty cp3 = superMan.getVars().get(3);
|
||||
Assert.assertEquals(cp3.name, "origin");
|
||||
Assert.assertTrue(cp3.required);
|
||||
|
||||
CodegenProperty cp4 = superMan.getVars().get(4);
|
||||
Assert.assertEquals(cp4.name, "category");
|
||||
Assert.assertFalse(cp4.required);
|
||||
|
||||
CodegenProperty cp5 = superMan.getVars().get(5);
|
||||
Assert.assertEquals(cp5.name, "level");
|
||||
Assert.assertTrue(cp5.required);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test(description = "test example string imported from x-example parameterr (OAS2)")
|
||||
public void exampleStringFromExampleParameterOAS2Test() {
|
||||
final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/petstore-nullable.yaml");
|
||||
|
@ -0,0 +1,63 @@
|
||||
openapi: 3.0.1
|
||||
info:
|
||||
version: 1.0.0
|
||||
title: Example
|
||||
license:
|
||||
name: MIT
|
||||
servers:
|
||||
- url: http://api.example.xyz/v1
|
||||
paths:
|
||||
/person/display/{personId}:
|
||||
get:
|
||||
parameters:
|
||||
- name: personId
|
||||
in: path
|
||||
required: true
|
||||
description: The id of the person to retrieve
|
||||
schema:
|
||||
type: string
|
||||
operationId: list
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/SuperMan"
|
||||
components:
|
||||
schemas:
|
||||
SuperMan:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/Human'
|
||||
- $ref: '#/components/schemas/Hero'
|
||||
- type: object
|
||||
required:
|
||||
- level
|
||||
properties:
|
||||
category:
|
||||
type: string
|
||||
level:
|
||||
type: integer
|
||||
Hero:
|
||||
description: Hero
|
||||
type: object
|
||||
required:
|
||||
- origin
|
||||
properties:
|
||||
reward:
|
||||
type: integer
|
||||
format: int64
|
||||
origin:
|
||||
type: string
|
||||
Human:
|
||||
description: Human
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
example: Tom
|
Loading…
x
Reference in New Issue
Block a user