Skip to content

'allOf' not processed correctly for property #1777

@devdevx

Description

@devdevx

Example with one schema property:

openapi: "3.0.0"
info:
  title: API-Template
  description: |
    Single or multilined API description. Can be written on HTML or [CommonMark](http://commonmark.org/help/)
  version: v1

tags:
  - name: Customers
    description: "Operations and resources related to customers"

paths:
  /customers/{customerId}:
    parameters:
      - $ref: '#/components/parameters/customerIdPathParam'
    get:
      summary: Retrieve customer information
      description: Description for operation that allows retrieve customer information
      operationId: retrieveCustomerInfo
      tags:
        - Customers
      responses:
        '200':
          description: Customer response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/customer'

components:
  parameters:
    customerIdPathParam:
      name: customerId
      in: path
      required: true
      description: The id of the customer
      schema:
        $ref: '#/components/schemas/uuid'

  schemas:
    uuid:
      type: string
      format: uuid
      minLength: 36
      maxLength: 36
      pattern: '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'

    customer:
      type: object
      properties:
        id:
          description: The id of the customer
          allOf:
           - $ref: '#/components/schemas/uuid'
          x-apigen-mapping:
            field: id

Code executed:

import io.swagger.v3.core.util.Yaml;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.OpenAPIV3Parser;
import io.swagger.v3.parser.core.models.ParseOptions;
import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

public class Main {
    public static void main(String[] args) throws IOException {
        String api;
        try (InputStream is = Main.class.getClassLoader().getResourceAsStream("template_error.yaml")) {
            api = IOUtils.toString(is, StandardCharsets.UTF_8);
        }
        OpenAPIV3Parser parser = new OpenAPIV3Parser();
        ParseOptions options = new ParseOptions();
        options.setResolve(true);
        options.setResolveCombinators(true);
        options.setResolveFully(true);
        options.setFlatten(true);
        OpenAPI openAPI = parser.readContents(api, null, options).getOpenAPI();
        System.out.println(Yaml.mapper().writeValueAsString(openAPI));
    }
}

Output:

openapi: 3.0.0
info:
  title: API-Template
  description: |
    Single or multilined API description. Can be written on HTML or [CommonMark](http://commonmark.org/help/)
  version: v1
servers:
  - url: /
tags:
  - name: Customers
    description: Operations and resources related to customers
paths:
  /customers/{customerId}:
    get:
      tags:
        - Customers
      summary: Retrieve customer information
      description: Description for operation that allows retrieve customer information
      operationId: retrieveCustomerInfo
      parameters:
        - name: customerId
          in: path
          description: The id of the customer
          required: true
          style: simple
          explode: false
          schema:
            maxLength: 36
            minLength: 36
            pattern: "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
            type: string
            format: uuid
      responses:
        "200":
          description: Customer response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/inline_response_200'
components:
  schemas:
    uuid:
      maxLength: 36
      minLength: 36
      pattern: "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
      type: string
      format: uuid
    customer:
      type: object
      properties:
        id: {}
    inline_response_200:
      type: object
      properties:
        id: {}
  parameters:
    customerIdPathParam:
      name: customerId
      in: path
      description: The id of the customer
      required: true
      style: simple
      explode: false
      schema:
        maxLength: 36
        minLength: 36
        pattern: "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
        type: string
        format: uuid

Expected result:

The id property in the customer and inline_response_200 schemas should have content and not be an empty object.

Tried with versions 2.0.33 and 2.1.1 with same result.

    <dependencies>
        <dependency>
            <groupId>io.swagger.parser.v3</groupId>
            <artifactId>swagger-parser</artifactId>
            <!-- <version>2.0.33</version>-->
            <version>2.1.1</version>
        </dependency>
    </dependencies>

Seems a similar issue to #1367 but that was closed.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions