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

Upgrade openapi3-ts to v3.0.0 #139

Open
afraz-khan opened this issue Feb 8, 2023 · 4 comments
Open

Upgrade openapi3-ts to v3.0.0 #139

afraz-khan opened this issue Feb 8, 2023 · 4 comments

Comments

@afraz-khan
Copy link

afraz-khan commented Feb 8, 2023

Finding type issues while using routing-controllers-openapi:v4.0.0 with latest class-validator-jsonschema .

public buildSpec() {
    const {defaultMetadataStorage} = require('class-transformer/cjs/storage');
    const routingControllersOptions = {
      routePrefix: '/api',
    };
    const storage = getMetadataArgsStorage();
    const schemas = validationMetadatasToSchemas({
      classTransformerMetadataStorage: defaultMetadataStorage,
      refPointerPrefix: '#/components/schemas/',
    });

    // storage.controllers = storage.controllers.filter(c => this.isDisplayed(c.target));
    // storage.actions = storage.actions.filter(c => this.isDisplayed(c.target));

    const spec = routingControllersToSpec(storage, routingControllersOptions, {
      components: {
        schemas,
        securitySchemes: {
          basicAuth: {
            scheme: 'basic',
            type: 'http',
          },
        },
      },
      info: {
        title: 'API schema',
        version: 'v1',
      },
    });

    return spec;
  }
[ERROR] 17:41:10 ⨯ Unable to compile TypeScript:
src/service/OpenApi.ts(24,9): error TS2322: Type 'Record<string, SchemaObject>' is not assignable to type '{ [schema: string]: ReferenceObject | SchemaObject; }'.
  'string' index signatures are incompatible.
    Type 'SchemaObject' is not assignable to type 'ReferenceObject | SchemaObject'.
      Type 'import("/Users/apple/work/byg/byg-admin-core/node_modules/class-validator-jsonschema/node_modules/openapi3-ts/dist/mjs/model/OpenApi").SchemaObject' is not assignable to type 'import("/Users/apple/work/byg/byg-admin-core/node_modules/openapi3-ts/dist/model/OpenApi").SchemaObject'.
        Types of property 'type' are incompatible.
          Type 'SchemaObjectType | SchemaObjectType[] | undefined' is not assignable to type '"string" | "number" | "boolean" | "object" | "integer" | "null" | "array" | undefined'.
            Type 'SchemaObjectType[]' is not assignable to type '"string" | "number" | "boolean" | "object" | "integer" | "null" | "array" | undefined'.

I think, openapi3-ts dependency needs an upgrade, it currently conflicts with its counterpart in class-validator-jsonschema.

(ps: Type assertions are a workaround.)

@osnipezzini
Copy link

Do you make some fix to this ? I maked Type assertions but schemas and spec are not generating as expected.

Routes are generated, but on swagger don't have schemas

@afraz-khan
Copy link
Author

@osnipezzini couldn't find any proper solution, had to downgrade to version 3.1.0.

@stt-mtel
Copy link

I got the same issue, this is how i solved it

import type { SchemaObject } from 'openapi3-ts';
...
const schemas = validationMetadatasToSchemas({
  refPointerPrefix: '#/components/schemas/',
}) as { [schema: string]: SchemaObject };

@osnipezzini
Copy link

Thanks @afraz-khan and @stt-mtel but i decided to move to TSOA because of cleaner and working implementation.

I tryed downgrade too, but stills swagger not generating schemas fine.

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

3 participants