-
Notifications
You must be signed in to change notification settings - Fork 1.1k
refactor: clean usage of OAI's ExtensionValue #1271
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
Conversation
jannyHou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just curious, any reason to export ExtensionValue from openapi-spec-builder instead of openapi-v3?
And one minor comment.
| export function jsonToSchemaObject(jsonDef: JsonDefinition): SchemaObject { | ||
| const json = jsonDef as {[name: string]: ExtensionValue}; // gets around index signature error | ||
| // tslint:disable-next-line:no-any | ||
| const json = jsonDef as {[name: string]: any}; // gets around index signature error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, any reason changing ExtensionValue to any? I thought this PR aims at importing ExtensionValue from openapi-spec-builder.
Not a big deal though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON Definition is a JSON Schema object containing well-known keys and values:
export interface JsonDefinition extends Definition {
allOf?: JsonDefinition[];
oneOf?: JsonDefinition[];
anyOf?: JsonDefinition[];
items?: JsonDefinition | JsonDefinition[];
additionalItems?: {
anyOf: JsonDefinition[];
};
enum?: PrimitiveType[] | JsonDefinition[];
additionalProperties?: JsonDefinition | boolean;
definitions?: {[definition: string]: JsonDefinition};
properties?: {[property: string]: JsonDefinition};
}There are not OpenAPI spec extensions involved AFAICT, therefore we should not be using ExtensionValue type.
Based on the comment in the code, my understanding is that we need to cast from JsonDefinition to a string-key-to-any-value object/map to fix a compiler error in the default case below:
default:
result[property] = json[property];
break;I found a more elegant way how solve this problem by casting property to keyof JsonDefinition, see 8de9b75.
|
|
||
| export interface Extendable { | ||
| [extension: string]: ExtensionValue; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extendable should be Extensible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use ISpecificationExtension instead of Extendable. However, openapi3-ts does not come with any alias type similar to our ExtensionValue, that's why I thought it's better to preserve both our types.
OTOH, this is not a big deal. I think the benefits of using ISpecificationExtension are worth it.
I have updated the code accordingly, see a9e4ab9.
d8fef35 to
a9e4ab9
Compare
@jannyHou since Based on Raymond's feedback, I removed this type alias entirely. @raymondfeng @jannyHou PTAL again. I'll clean up the git commit history (squash all commits to a single one) after the patch gets approved. |
jannyHou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any or any alias are both fine to me, as long as the usages are identical across all packages.
👍 LGTM!
Remove the definition of ExtensionValue from openapi-v3-types as it is no longer used. Remove Extendable type from openapi-spec-builder and use ISpecificationExtension from openapi3-ts instead. Fix openapi type guards to use a more correct `object` type instead of `ExtensionValue`, since the guards are not dealing with any extensions. Fix json-to-schema converter to use a different workaround for the compiler error related to accessing index properties on a type without any indexer.
a9e4ab9 to
e154e57
Compare
Move the definition of ExtensionValue from openapi-v3-types (where it is no longer used) to openapi-spec-build.
Fix openapi type guards to use a more correct
objecttype instead ofExtensionValue, since the guards are not dealing with any extensions.Fixa json-to-schema converter to use
anyinstead ofExtensionValuewhen converting a JSON Schema object to an indexable object.This is a follow-up for #1265.
Checklist
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated