Skip to content

Model's fields generated from component schemas are empty. #1178

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

Open
chanced opened this issue Aug 3, 2022 · 3 comments
Open

Model's fields generated from component schemas are empty. #1178

chanced opened this issue Aug 3, 2022 · 3 comments
Assignees

Comments

@chanced
Copy link

chanced commented Aug 3, 2022

Using this 3.0 openapi spec:

openapi: "3.0.0"
info:
    version: 1.0.0
    title: Authenticated API Example
    description: An example API which uses bearer token scopes and JWT auth
paths:
    /things:
        get:
            operationId: listThings
            description: |
                Returns a list of things. Because this endpoint doesn't override the
                global security, it requires a JWT for authentication.
            responses:
                200:
                    description: a list of things
                    content:
                        application/json:
                            schema:
                                type: array
                                items:
                                    $ref: "#/components/schemas/ThingWithID"
        post:
            operationId: addThing
            description: |
                Adds a thing to the list of things. This endpoints overrides the global
                security scheme and requires a `things:w` scope in order to perform a
                write.
            security:
                - BearerAuth:
                      - "things:w"
            requestBody:
                description: A thing to insert. Returns the inserted thing with an ID
                required: true
                content:
                    application/json:
                        schema:
                            $ref: "#/components/schemas/Thing"
            responses:
                201:
                    description: The inserted Thing with a unique ID
                    content:
                        application/json:
                            schema:
                                type: array
                                items:
                                    $ref: "#/components/schemas/ThingWithID"
components:
    schemas:
        Thing:
            properties:
                name:
                    type: string
            required:
                - name
        ThingWithID:
            allOf:
                - $ref: "#/components/schemas/Thing"
                - properties:
                      id:
                          type: integer
                          format: int64
                  required:
                      - id
        Error:
            required:
                - code
                - message
            properties:
                code:
                    type: integer
                    format: int32
                    description: Error code
                message:
                    type: string
                    description: Error message
    securitySchemes:
        BearerAuth:
            type: http
            scheme: bearer
            bearerFormat: JWT
security:
    - BearerAuth: []

produces:

/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type Thing = {
};
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { Thing } from './Thing';

export type ThingWithID = Thing;

The Thing and ThingWithID types are both empty.

Screen Shot 2022-08-03 at 2 52 46 PM

Also, ThingWithID should be:

export type ThingWithID = Thing & { id: number }

Or something similar, but I'm assuming this has to do with the fact that neither type is being read properly.

@chanced chanced changed the title component schemas fields are blank. Model fields generated from component schemas are empty. Aug 3, 2022
@chanced chanced changed the title Model fields generated from component schemas are empty. Model's fields generated from component schemas are empty. Aug 3, 2022
@garcipat
Copy link

Is there anything new on this one? I'm still having that issue and have no idea on how to continue. Like this the package is unusable.

@akinnee
Copy link

akinnee commented Sep 23, 2022

Also having a similar issue. Does it have something to do with allOf? I did not have this problem with another spec that doesn't use allOf.

@danmichaelo
Copy link

danmichaelo commented Aug 16, 2023

We ran into the same problem. Seems like the generator fails to interpret objects unless type: object is set explicitly:

        Thing:
+           type: object
            properties:
                name:
                    type: string
            required:
                - name

Seems like most tooling allows type: object to be missing, and neither Spectral nor Redocly complains. I've tried to dig into the JSON schema specifications to verify that it can indeed be implicit, but it's a really hard read.

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

No branches or pull requests

5 participants