OpenAPIObject.paths usage
fmonniot opened this issue · comments
Hello there,
First thanks for the heavy lifting done in this library, it's a pleasure to not have to implement the OAI spec in typescript :)
A quick question regarding the OpenAPIObject
's paths
property.
I'm trying to get a get
OperationObject
from the main OpenAPI object, so I would say I should do something like openapi.paths['/my/path'].get
, which doesn't compile. So I went looking at the definition, and found:
interface OpenAPIObject extends ISpecificationExtension {
paths: {[path: string]: PathObject };
}
export interface PathObject extends ISpecificationExtension {
[path: string]: PathItemObject | any;
}
export interface PathItemObject extends ISpecificationExtension {
get?: OperationObject;
}
Why is there two indexed object ? The specification tells us that the first {[path: string]: PathObject }
should be a PathsObject
but maybe there is reason for the other indirection ?
Thanks,
François
Hi @fmonniot
The ISpecificationExtension
is there to support custom extensions. Basically, any starting with prefix: x-
They can be included in many parts of the spec.
If you read carefully on the PathObject Spec you can read: "This object MAY be extended with Specification Extensions."
That's why, we cannot full strongly type the indexer to be a PathsObject.
In any way, I am thinking, to extend the interface with two methods: one to get paths by key strongly-typed and another one to extract extensions: x-
as any.
Regards,
Hi. Added some support functions to make it easy to work with extensions:
- See
getExtension()
andsetExtension()
at lines 4-16. - Also
getPath()
at lines 70-75 - And a pair of test showing how to use them.
Closing this issue with this. Feel free to reopen if needed.
Awesome, thank you.
And a big +1 for the reactivity :)