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

Suffix support to the schema name and why numbers are appended to schema name like Note2 #404

Closed
anuraggo opened this issue Jun 24, 2021 · 3 comments

Comments

@anuraggo
Copy link

anuraggo commented Jun 24, 2021

Hello,

Is there any way we can add a suffix/prefix to the model Definitions like below:

type <defintion_name>_responseSuffix {

}

Also, I have observed that openapi-to-graphql appends number to the defintions name such as Note2
May I know how can we omit this or bypass If I want to display only Note ?
@Alan-Cha Can you please help me here ?

@anuraggo anuraggo changed the title Suffix support to the name of Definitions and numbers appended to Defintion name like Note2 Suffix support to the schema name and why numbers are appended to schema name like Note2 Jun 25, 2021
@Alan-Cha
Copy link
Collaborator

Alan-Cha commented Jul 1, 2021

@anuraggo Again, sorry for the delay. We recently merged in #399 (see #379 for the discussion). This adds the ability to add extensions in the OAS to define custom type and field names.

To clarify, appending numbers is intended when multiple types or fields share the same "preferred" name, aka the derived name from references, properties, etc. Most likely there is another type in your generated GraphQL interface that has the name Note.

@Alan-Cha
Copy link
Collaborator

Alan-Cha commented Jul 1, 2021

I need to make a new release but the extensions are your recommended solution.


Edit: Try v2.4.0 and see the following: https://github.com/IBM/openapi-to-graphql/tree/master/packages/openapi-to-graphql#custom-type-and-field-names-and-enum-values

@Alan-Cha Alan-Cha closed this as completed Jul 1, 2021
@anuraggo
Copy link
Author

anuraggo commented Jul 2, 2021

Hello @Alan-Cha ,

Thanks for your reply.

Usage of OAS extensions needs updating the swagger schema annd I don't have that option to update it.Hence I have tried writing below wrapper to modify the OAS js-object to insert the extension before invoking the method createGraphQLSchema. It is updating the oas object properly but not in the graphql schema .

const definitions = oass[oasKey].definitions || {};
Object.keys(definitions).forEach(definitionName => {
oass[oasKey].definitions[definitionName] = {
...oass[oasKey].definitions[definitionName],
'x-graphql-type-name': definitionName + '_responseSuffix'
}
});

This is updating the oas object as :

SystemListValue: {
type: 'object',
properties: {
name: [Object],
validFor: [Object],
localizedName: [Object],
displayProperties: [Object]
},
description: 'Single valid value of a list.',
'x-graphql-type-name': 'SystemListValue_responseSuffix'
}

But the final graphql output schema is not appending the suffix for all the types.

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

2 participants