forked from loafle/openapi-generator-original
		
	Compare commits
	
		
			5 Commits
		
	
	
		
			master
			...
			fix-oneof-
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					66f8d15e75 | ||
| 
						 | 
					b2e51982c0 | ||
| 
						 | 
					01584fed76 | ||
| 
						 | 
					19f307d6cd | ||
| 
						 | 
					754207a636 | 
@ -430,14 +430,14 @@ public class ModelUtils {
 | 
			
		||||
     * <p>
 | 
			
		||||
     * For example, an OpenAPI schema is considered an ObjectSchema in the following scenarios:
 | 
			
		||||
     * <p>
 | 
			
		||||
     *
 | 
			
		||||
     *   type: object
 | 
			
		||||
     *   additionalProperties: false
 | 
			
		||||
     *   properties:
 | 
			
		||||
     *     name:
 | 
			
		||||
     *       type: string
 | 
			
		||||
     *     address:
 | 
			
		||||
     *       type: string
 | 
			
		||||
     * <p>
 | 
			
		||||
     * type: object
 | 
			
		||||
     * additionalProperties: false
 | 
			
		||||
     * properties:
 | 
			
		||||
     *   name:
 | 
			
		||||
     *   type: string
 | 
			
		||||
     * address:
 | 
			
		||||
     *   type: string
 | 
			
		||||
     *
 | 
			
		||||
     * @param schema the OAS schema
 | 
			
		||||
     * @return true if the specified schema is an Object schema.
 | 
			
		||||
@ -527,28 +527,28 @@ public class ModelUtils {
 | 
			
		||||
     * A MapSchema differs from an ObjectSchema in the following way:
 | 
			
		||||
     * - An ObjectSchema is not extensible, i.e. it has a fixed number of properties.
 | 
			
		||||
     * - A MapSchema is an object that can be extended with an arbitrary set of properties.
 | 
			
		||||
     * The payload may include dynamic properties.
 | 
			
		||||
     *   The payload may include dynamic properties.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * Note that isMapSchema returns true for a composed schema (allOf, anyOf, oneOf) that also defines
 | 
			
		||||
     * additionalproperties.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * For example, an OpenAPI schema is considered a MapSchema in the following scenarios:
 | 
			
		||||
     * <p>
 | 
			
		||||
     *
 | 
			
		||||
     * <p>
 | 
			
		||||
     * type: object
 | 
			
		||||
     * additionalProperties: true
 | 
			
		||||
     * <p>
 | 
			
		||||
     * type: object
 | 
			
		||||
     * additionalProperties:
 | 
			
		||||
     *   type: object
 | 
			
		||||
     *   additionalProperties: true
 | 
			
		||||
     *
 | 
			
		||||
     *   type: object
 | 
			
		||||
     *   additionalProperties:
 | 
			
		||||
     *     type: object
 | 
			
		||||
     *     properties:
 | 
			
		||||
     *       code:
 | 
			
		||||
     *         type: integer
 | 
			
		||||
     *
 | 
			
		||||
     *   allOf:
 | 
			
		||||
     *     - $ref: '#/components/schemas/Class1'
 | 
			
		||||
     *     - $ref: '#/components/schemas/Class2'
 | 
			
		||||
     *   additionalProperties: true
 | 
			
		||||
     * <p>
 | 
			
		||||
     * allOf:
 | 
			
		||||
     *   - $ref: '#/components/schemas/Class1'
 | 
			
		||||
     *   - $ref: '#/components/schemas/Class2'
 | 
			
		||||
     * additionalProperties: true
 | 
			
		||||
     *
 | 
			
		||||
     * @param schema the OAS schema
 | 
			
		||||
     * @return true if the specified schema is a Map schema.
 | 
			
		||||
@ -857,7 +857,7 @@ public class ModelUtils {
 | 
			
		||||
     *         The value can be any type except the 'null' value.
 | 
			
		||||
     *
 | 
			
		||||
     * @param schema  potentially containing a '$ref'
 | 
			
		||||
     * @param openAPI  document containing the Schema.
 | 
			
		||||
     * @param openAPI document containing the Schema.
 | 
			
		||||
     * @return true if it's a free-form object
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isFreeFormObject(Schema schema, OpenAPI openAPI) {
 | 
			
		||||
@ -999,8 +999,8 @@ public class ModelUtils {
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the schema referenced by $ref to schema's properties, e.g. #/components/schemas/Pet/properties/category.
 | 
			
		||||
     *
 | 
			
		||||
     * @param openAPI    specification being checked
 | 
			
		||||
     * @param refString  schema reference
 | 
			
		||||
     * @param openAPI   specification being checked
 | 
			
		||||
     * @param refString schema reference
 | 
			
		||||
     * @return schema
 | 
			
		||||
     */
 | 
			
		||||
    public static Schema getSchemaFromRefToSchemaWithProperties(OpenAPI openAPI, String refString) {
 | 
			
		||||
@ -1021,7 +1021,7 @@ public class ModelUtils {
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns true if $ref to a reference to schema's properties, e.g. #/components/schemas/Pet/properties/category.
 | 
			
		||||
     *
 | 
			
		||||
     * @param refString  schema reference
 | 
			
		||||
     * @param refString schema reference
 | 
			
		||||
     * @return true if $ref to a reference to schema's properties
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isRefToSchemaWithProperties(String refString) {
 | 
			
		||||
@ -1198,7 +1198,7 @@ public class ModelUtils {
 | 
			
		||||
    /**
 | 
			
		||||
     * Return the first defined Schema for a ApiResponse
 | 
			
		||||
     *
 | 
			
		||||
     * @param openAPI OpenAPI spec.
 | 
			
		||||
     * @param openAPI  OpenAPI spec.
 | 
			
		||||
     * @param response API response of the operation
 | 
			
		||||
     * @return firstSchema
 | 
			
		||||
     */
 | 
			
		||||
@ -1218,13 +1218,13 @@ public class ModelUtils {
 | 
			
		||||
     * for the 'application/json' content type because it is listed first in the OAS.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * responses:
 | 
			
		||||
     *   '200':
 | 
			
		||||
     *     content:
 | 
			
		||||
     *       application/json:
 | 
			
		||||
     *         schema:
 | 
			
		||||
     *           $ref: '#/components/schemas/XYZ'
 | 
			
		||||
     *       application/xml:
 | 
			
		||||
     *          ...
 | 
			
		||||
     * '200':
 | 
			
		||||
     * content:
 | 
			
		||||
     * application/json:
 | 
			
		||||
     * schema:
 | 
			
		||||
     * $ref: '#/components/schemas/XYZ'
 | 
			
		||||
     * application/xml:
 | 
			
		||||
     * ...
 | 
			
		||||
     *
 | 
			
		||||
     * @param content a 'content' section in the OAS specification.
 | 
			
		||||
     * @return the Schema.
 | 
			
		||||
@ -1427,7 +1427,7 @@ public class ModelUtils {
 | 
			
		||||
     * any additional properties are allowed. This is equivalent to setting additionalProperties
 | 
			
		||||
     * to the boolean value True or setting additionalProperties: {}
 | 
			
		||||
     *
 | 
			
		||||
     * @param schema  the input schema that may or may not have the additionalProperties keyword.
 | 
			
		||||
     * @param schema the input schema that may or may not have the additionalProperties keyword.
 | 
			
		||||
     * @return the Schema of the additionalProperties. The null value is returned if no additional
 | 
			
		||||
     * properties are allowed.
 | 
			
		||||
     */
 | 
			
		||||
@ -1540,19 +1540,19 @@ public class ModelUtils {
 | 
			
		||||
     * because 'Animal' specifies a discriminator.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * animal:
 | 
			
		||||
     *   type: object
 | 
			
		||||
     *   discriminator:
 | 
			
		||||
     *     propertyName: type
 | 
			
		||||
     *   properties:
 | 
			
		||||
     *     type: string
 | 
			
		||||
     * type: object
 | 
			
		||||
     * discriminator:
 | 
			
		||||
     * propertyName: type
 | 
			
		||||
     * properties:
 | 
			
		||||
     * type: string
 | 
			
		||||
     *
 | 
			
		||||
     * <p>
 | 
			
		||||
     * dog:
 | 
			
		||||
     *   allOf:
 | 
			
		||||
     *      - $ref: '#/components/schemas/animal'
 | 
			
		||||
     *      - type: object
 | 
			
		||||
     *        properties:
 | 
			
		||||
     *          breed: string
 | 
			
		||||
     * allOf:
 | 
			
		||||
     * - $ref: '#/components/schemas/animal'
 | 
			
		||||
     * - type: object
 | 
			
		||||
     * properties:
 | 
			
		||||
     * breed: string
 | 
			
		||||
     *
 | 
			
		||||
     * @param composedSchema schema (alias or direct reference)
 | 
			
		||||
     * @param allSchemas     all schemas
 | 
			
		||||
@ -1683,7 +1683,7 @@ public class ModelUtils {
 | 
			
		||||
     * If it's string, return true if it's non-empty.
 | 
			
		||||
     * If the return value is `true`, the schema is a parent.
 | 
			
		||||
     *
 | 
			
		||||
     * @param schema    Schema
 | 
			
		||||
     * @param schema Schema
 | 
			
		||||
     * @return boolean
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isExtensionParent(Schema schema) {
 | 
			
		||||
@ -1750,9 +1750,9 @@ public class ModelUtils {
 | 
			
		||||
     * type is one of the elements under 'oneOf'.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * OptionalOrder:
 | 
			
		||||
     *   oneOf:
 | 
			
		||||
     *     - type: 'null'
 | 
			
		||||
     *     - $ref: '#/components/schemas/Order'
 | 
			
		||||
     * oneOf:
 | 
			
		||||
     * - type: 'null'
 | 
			
		||||
     * - $ref: '#/components/schemas/Order'
 | 
			
		||||
     *
 | 
			
		||||
     * @param schema the OAS composed schema.
 | 
			
		||||
     * @return true if the composed schema is nullable.
 | 
			
		||||
@ -1935,7 +1935,7 @@ public class ModelUtils {
 | 
			
		||||
    private static void logWarnMessagesForIneffectiveValidations(Set<String> setValidations, Schema schema, Set<String> effectiveValidations) {
 | 
			
		||||
        setValidations.removeAll(effectiveValidations);
 | 
			
		||||
        setValidations.stream().forEach(validation -> {
 | 
			
		||||
            LOGGER.warn("Validation '" + validation + "' has no effect on schema '" + getType(schema) +"'. Ignoring!");
 | 
			
		||||
            LOGGER.warn("Validation '" + validation + "' has no effect on schema '" + getType(schema) + "'. Ignoring!");
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -2214,9 +2214,8 @@ public class ModelUtils {
 | 
			
		||||
     * <p>
 | 
			
		||||
     * Return true if the schema's type is 'null' or not specified
 | 
			
		||||
     *
 | 
			
		||||
     * @param schema Schema
 | 
			
		||||
     * @param schema  Schema
 | 
			
		||||
     * @param openAPI OpenAPI
 | 
			
		||||
     *
 | 
			
		||||
     * @return true if schema is null type
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isNullTypeSchema(OpenAPI openAPI, Schema schema) {
 | 
			
		||||
@ -2260,11 +2259,14 @@ public class ModelUtils {
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // for `type: null`
 | 
			
		||||
            if (schema.getTypes() == null && schema.get$ref() == null) {
 | 
			
		||||
            if (schema.getTypes() == null && schema.get$ref() == null
 | 
			
		||||
                    && schema.getDescription() == null) { // ensure it's not schema with just a description
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        } else { // 3.0.x or 2.x spec
 | 
			
		||||
            if ((schema.getType() == null || schema.getType().equals("null")) && schema.get$ref() == null) {
 | 
			
		||||
            if ((schema.getType() == null || schema.getType().equals("null"))
 | 
			
		||||
                    && schema.get$ref() == null
 | 
			
		||||
                    && schema.getDescription() == null) { // ensure it's not schema with just a description
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@ -2277,9 +2279,8 @@ public class ModelUtils {
 | 
			
		||||
     * <p>
 | 
			
		||||
     * Return true if the schema can be handled by OpenAPI Generator
 | 
			
		||||
     *
 | 
			
		||||
     * @param schema Schema
 | 
			
		||||
     * @param schema  Schema
 | 
			
		||||
     * @param openAPI OpenAPIs
 | 
			
		||||
     *
 | 
			
		||||
     * @return true if schema is null type
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isUnsupportedSchema(OpenAPI openAPI, Schema schema) {
 | 
			
		||||
@ -2290,7 +2291,7 @@ public class ModelUtils {
 | 
			
		||||
        // dereference the schema
 | 
			
		||||
        schema = ModelUtils.getReferencedSchema(openAPI, schema);
 | 
			
		||||
 | 
			
		||||
        if (schema.getTypes() == null && hasValidation(schema))  {
 | 
			
		||||
        if (schema.getTypes() == null && hasValidation(schema)) {
 | 
			
		||||
            // just validation without type
 | 
			
		||||
            return true;
 | 
			
		||||
        } else if (schema.getIf() != null && schema.getThen() != null) {
 | 
			
		||||
 | 
			
		||||
@ -497,9 +497,22 @@ public class ModelUtilsTest {
 | 
			
		||||
 | 
			
		||||
        schema = openAPI.getComponents().getSchemas().get("AnyOfTest");
 | 
			
		||||
        assertFalse(ModelUtils.isNullTypeSchema(openAPI, schema));
 | 
			
		||||
        // first element (getAnyOf().get(0)) is a string. no need to test
 | 
			
		||||
        assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(1)));
 | 
			
		||||
        assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(2)));
 | 
			
		||||
        assertTrue(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getAnyOf().get(3)));
 | 
			
		||||
 | 
			
		||||
        schema = openAPI.getComponents().getSchemas().get("OneOfRef");
 | 
			
		||||
        assertFalse(ModelUtils.isNullTypeSchema(openAPI, schema));
 | 
			
		||||
        assertFalse(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getOneOf().get(0)));
 | 
			
		||||
 | 
			
		||||
        schema = openAPI.getComponents().getSchemas().get("OneOfMultiRef");
 | 
			
		||||
        assertFalse(ModelUtils.isNullTypeSchema(openAPI, schema));
 | 
			
		||||
        assertFalse(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getOneOf().get(0)));
 | 
			
		||||
        assertFalse(ModelUtils.isNullTypeSchema(openAPI, (Schema) schema.getOneOf().get(1)));
 | 
			
		||||
 | 
			
		||||
        schema = openAPI.getComponents().getSchemas().get("JustDescription");
 | 
			
		||||
        assertFalse(ModelUtils.isNullTypeSchema(openAPI, schema));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
 | 
			
		||||
@ -58,7 +58,7 @@ components:
 | 
			
		||||
          $ref: '#/components/schemas/IntegerRef'
 | 
			
		||||
        number:
 | 
			
		||||
          anyOf:
 | 
			
		||||
            - $ref: '#/components/schemas/Number'
 | 
			
		||||
            - $ref: '#/components/schemas/StringRef'
 | 
			
		||||
    AnyOfStringArrayOfString:
 | 
			
		||||
      anyOf:
 | 
			
		||||
        - type: string
 | 
			
		||||
@ -85,6 +85,8 @@ components:
 | 
			
		||||
        - $ref: '#/components/schemas/IntegerRef'
 | 
			
		||||
    IntegerRef:
 | 
			
		||||
      type: integer
 | 
			
		||||
    StringRef:
 | 
			
		||||
      type: string
 | 
			
		||||
    OneOfAnyType:
 | 
			
		||||
      oneOf:
 | 
			
		||||
        - type: object
 | 
			
		||||
@ -93,4 +95,13 @@ components:
 | 
			
		||||
        - type: string
 | 
			
		||||
        - type: integer
 | 
			
		||||
        - type: array
 | 
			
		||||
          items: {}
 | 
			
		||||
          items: {}
 | 
			
		||||
    OneOfRef:
 | 
			
		||||
      oneOf:
 | 
			
		||||
        - $ref: '#/components/schemas/IntegerRef'
 | 
			
		||||
    OneOfMultiRef:
 | 
			
		||||
      oneOf:
 | 
			
		||||
        - $ref: '#/components/schemas/IntegerRef'
 | 
			
		||||
        - $ref: '#/components/schemas/StringRef'
 | 
			
		||||
    JustDescription:
 | 
			
		||||
      Description: A schema with just description
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user