Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema referenced in patternProperties is not embedded in bundled file #792

Closed
arvidfm opened this issue Aug 3, 2022 · 5 comments · Fixed by #1637
Closed

Schema referenced in patternProperties is not embedded in bundled file #792

arvidfm opened this issue Aug 3, 2022 · 5 comments · Fixed by #1637

Comments

@arvidfm
Copy link

arvidfm commented Aug 3, 2022

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.

@tatomyr
Copy link
Contributor

tatomyr commented Aug 4, 2022

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

@amiika
Copy link

amiika commented Oct 27, 2023

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

@tatomyr
Copy link
Contributor

tatomyr commented Oct 27, 2023

@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?

samdbmg added a commit to bbc/tams that referenced this issue Dec 19, 2023
Adds a script to rewrite part of the bundled API spec, to work around
Redocly not having support for `patternProperties` (see also bug
Redocly/redocly-cli#792)
samdbmg added a commit to bbc/tams that referenced this issue Dec 20, 2023
Adds a script to rewrite part of the bundled API spec, to work around
Redocly not having support for `patternProperties` (see also bug
Redocly/redocly-cli#792)
@kevin-lithic
Copy link

@tatomyr do you know if this is something that will be supported soon?

@tatomyr
Copy link
Contributor

tatomyr commented Jul 17, 2024

The fix is coming through. Thanks, @kevin-lithic, for bringing it to my attention!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants