redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

Schema referenced in patternProperties is not embedded in bundled file

Open arvidfm opened this issue 1 year ago • 3 comments

Describe the bug References to schemas defined in external files do not get embedded in components if present in a patternProperties definition of an object. Instead, the $ref still points to the external file even after bundling.

To Reproduce Steps to reproduce the behavior:

  1. Given this .redocly.yaml file
apis:
  main@v1:
    root: openapi/openapi.yaml
  1. And these OpenAPI files

openapi/openapi.yaml

openapi: 3.1.0
info:
  title: Test
  version: 1.0.0
paths:
  /asset/{assetId}:
    get:
      operationId: assetGetAsset
      summary: Fetch an asset
      requestBody:
        content:
          application/json:
            schema:
              type: object
              patternProperties:
                .*:
                  $ref: object.yaml

openapi/object.yaml

type: object
properties:
  id:
    type: integer
  1. Run this command with these arguments... openapi bundle -o dist
  2. See error

The resulting dist.yaml contains:

openapi: 3.1.0
info:
  title: Test
  version: 1.0.0
paths:
  /asset/{assetId}:
    get:
      operationId: assetGetAsset
      summary: Fetch an asset
      requestBody:
        content:
          application/json:
            schema:
              type: object
              patternProperties:
                .*:
                  $ref: object.yaml
components: {}

Note how the reference to object.yaml is still there.

Expected behavior The referenced schema should be embedded, something like:

openapi: 3.1.0
info:
  title: Test
  version: 1.0.0
paths:
  /asset/{assetId}:
    get:
      operationId: assetGetAsset
      summary: Fetch an asset
      requestBody:
        content:
          application/json:
            schema:
              type: object
              patternProperties:
                .*:
                  $ref: '#/components/schemas/object'
components:
  schemas:
    object:
      type: object
      properties:
        id:
          type: integer

Logs If applicable, add logs to help explain your problem.

OpenAPI definition See above

Redocly Version(s) What version of Redocly CLI are you using?

$ openapi --version
1.0.0-beta.105

Node.js Version(s) What version of node.js are you using?

$ node --version
v16.14.2

Additional context Add any other context about the problem here.

arvidfm avatar Aug 03 '22 18:08 arvidfm

Thank you for reporting this @arvidfm!

However, this is not a bug but rather an enhancement as we don't support patternProperties yet 🙂

BTW, in your exact case you can use additionalProperties instead of patternProperties:

additionalProperties:
  $ref: object.yaml

tatomyr avatar Aug 04 '22 09:08 tatomyr

This is still an issue. Tried to use $ref under patternProperties but it is not working.

Example:

title: Facts
type: object
description: A set of financial facts in xBRL-JSON format.
properties:
  facts:
    patternProperties:
      "^[a-zA-Z0-9_-]+$":
          properties:
            value:
              type: string
              example: '12223000'
            decimals:
              type: integer
              example: -3
            dimensions:
              $ref: './Dimensions.yaml'
          required:
            - value
            - dimensions
          example: shtag_10414

amiika avatar Oct 27 '23 11:10 amiika

@amiika yes, this is still to be implemented. Maybe you can try using additionalProperties instead? Is there a way to restrict the names of the properties other than using JSON schema for your case?

tatomyr avatar Oct 27 '23 12:10 tatomyr