Comments (32)
For SRP, local file loading should be omitted.
Just requires passing {id : SchemaObject}
hash to jsonschema
via express-openapi-validation
or express-openapi-response-validation
.
And also, of course, I want to pass it via initialize argument of express-openapi.
from open-api.
Can you try this?
$ref: 'http://json-schema.org/draft-04/schema#'
from open-api.
I got the same error 😢
from open-api.
@MugeSo this will likely take a decent amount of work. Have a look at https://github.com/tdegrunt/jsonschema#dereferencing-schemas. As you can see, we'd need to update each module that uses jsonschema
.
Given that, one of the designs of openapi is to be a limited subset of jsonschema. I'm curious to know what intentions you have in referencing http://json-schema.org/schema
?
from open-api.
@jsdevel
At first, i know i should use 'http://json-schema.org/draft-04/schema#', 'http://json-schema.org/schema' is my mistake.
The reason why I reference it is to contain external defined schema in api-doc is nonsense.
When api-doc contains them, it get large wastefully.
And as i said in #17 (comment) , i don't need dynamic loading.
So, deferencing-schemas
is not needed. just call v.addSchema
.
Like:
Object.keys(externalSchemas).forEach(function(key) {
v.addSchema(schemas[key], key);
});
If you want, I send PR to each modules 😉
from open-api.
PRs are welcomed!
from open-api.
@jsdevel
I fond $ref
of parameters object are also unresolved.
e.g:
parameters = [
{ $ref: '#/parameters/myparameter' }
]
And I considered about it and this again.
Now I think it's better to use json-refs or something to resolve any references(not only schema) in api doc.
How about?
from open-api.
So $ref
actually isn't listed as a valid property in parameters
. See the spec.
from open-api.
I usually use code to overcome this shortcoming of openapi/swagger
parameters: [
myParameterModule.myParameter
]
myParameterModule
looks like this:
myParameter: {
name: 'foo',
type: 'string',
in: 'query'
}
from open-api.
$ref
is valid.
See parameters
property.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#operationObject
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#path-item-object
https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json#L1482
from open-api.
I see it: https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json#L1482
Then it should work. Have you tried this?
parameters = [
{ $ref: '#/definitions/myparameter' }
]
from open-api.
It's wrong. parameters
property of Swagger Object
is for define parameters.
See:
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields
https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json#L186
from open-api.
And it doesn't work because openapi-jsonschema-parameters
doesn't handle that.
from open-api.
@MugeSo can you open a PR to address this? This is a good find.
from open-api.
Also resposes
property of `Operation Object'.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#responses-object
can you open a PR to address this? This is a good find.
I'll try it.
But it takes some time because it seems complex.
(And it's 3:25am here)
from open-api.
(And it's 3:25am here)
Go to bed! lol
from open-api.
Yea, I feel this would be a major addition to the framework. Perhaps we should track responses and parameters separately?
from open-api.
json-ref-lite looks pretty cool too.
from open-api.
I've seen json-ref-lite
.
It' nice except that it resolve reference start with http:
only through network.
This causes problem when schema host server is down.
However, unfortunately, other library i found is async.
If we async one, openapi.initialize
get async too :(
from open-api.
OTTOMH
var jsonRef = requrie('json-ref-lite');
var externalSchemas = args.externalSchemas || [];
// create id based reference map
var ids = jsonRef.findId(externalSchemas.concat(apiDoc.definitions));
var resolved = copy(methodDoc);// json-ref-lite is destractive
jsonRef.replace(resolved, ids, apiDoc);
from open-api.
The reason why use only apiDoc.definitions
is Reference Object supports only canonical reference.
schema
properties are JSON Schema Object and it has own $ref
definition in spec.
$ref - As a JSON Reference
from open-api.
Sorry, in the previous code, ids
include all ids in externalSchemas.
And external thing not only schema.
var jsonRef = requrie('json-ref-lite');
// id -> json object map
var externalJsons = copy(args.externalJsons) || {};
// create id based reference map
var ids = shallowMerge(jsonRef.findId(apiDoc.definitions), externalSchemas);
var resolvedMethodDoc = jsonRef.replace(copy(methodDoc), ids, apiDoc); // json-ref-lite is destractive
from open-api.
Finally:
// id -> json object map
jsonRef.cache = copy(args.externalJsons) || {};
var resolvedMethodDoc = jsonRef.replace(
copy(methodDoc), // json-ref-lite is destractive
jsonRef.findId(apiDoc.definitions),
apiDoc
);
OK, I send PR soon.
from open-api.
Unfortunately, current implementation works with invalid reference like:
{
responses: {
200: {
$ref: '#/definitions/User'
},
default: {
$ref: '#/definitions/Error'
}
}
};
This should be:
{
responses: {
200: {
$ref: '#/responses/User'
},
default: {
$ref: '#/responses/Error'
}
}
};
// with apiDoc
{
responses: {
User: {
description: "Response for user representation",
schema: { $ref: "#/definitions/User" }
},
Error: {
description: "Generic error response",
schema: { $ref: "#/definitions/Error" }
}
}
See: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#responses-object
So, what should I do? Can I cause BC break?
If so, it takes more time because i need fix some tests existing.
from open-api.
Let me take a crack at this. After thinking about it some more, I feel I have a simple solution.
from open-api.
I found simple solution too.
function wrongReferenceCorrected(responses) {
var fixed = copy(responses);
for(statusCode in responses) {
if (responses[statusCode].$ref && /^#\/definitions\//.testr(esponses[statusCode].$ref) {
responses[statusCode] = {
description: statusCode + " Response",
schema: responses[statusCode]
};
console.warn(loggingKey, 'Correct wrong refernce. methodDoc.responses.statusCode.$ref can be only "#/responses/responseName"');
}
}
}
from open-api.
from open-api.
@MugeSo with version v0.16.0
, parameters
and responses
have support for local $ref
s whereas before they didn't. If you can submit a PR for external refs then that would be great. Thanks for all your contributions!
from open-api.
@MugeSo after looking into json-ref-lite
a bit more, I have a few things about it that I'm not sure would be good for express-openapi
:
- It's relying on
spawnSync
which is available in the latest versions of node, but isn't in older versions. - When
spawnSync
isn't available, it tries to install a native add on. I'd really like to avoid native add ons if at all possible. - Initialization time will increase with the added latency.
It may be better to update express-openapi-validation
and express-openapi-response-validation
to use jsonschema
's async loading features for external schemas.
from open-api.
spawnSync
is used in sync-request
right?
But it's just optional.
No network access is needed when jsonRef.cache
has every external JSONs.
My solution do that.
from open-api.
After coderofsalvation/json-ref-lite#2 is merged, i'll send PR ;)
from open-api.
Closed by #30 .
from open-api.
Related Issues (20)
- express-openapi: Unclear how to validate successful completion of tutorial HOT 5
- pnpm and glob issue in express-openapi
- Add application/json content type support in openapi-request-coercer
- Add support for `prefixItems` HOT 3
- SyntaxError: Invalid regular expression during path-to-regexp conversion HOT 4
- openapi-framework: fixed windows path names HOT 4
- [enhancement] openapi-response-validator: native ESM node modules default export not working as intended HOT 3
- [ft. request] openapi-response-validator - allow access to response param in errorTransformer HOT 1
- Using automatic paths with ESM HOT 2
- OpenAPI Types package, Path Item Object HOT 1
- Supertest integration tests fail after update to express-openapi 12.x.x
- parameters from Swagger 2.0 (openapi 2.0) YAML file are not caught by express-openapi HOT 2
- parameters from Swagger 2.0 (openapi 2.0) YAML file are not caught by express-openapi
- External refs not captured in parameters for request validation HOT 1
- Bug: OpenAPIResponseValidatorArgs responses object incorrectly defined
- Support for Asynchronous Custom Keywords in openapi-request-validator
- Support for validating OpenAPI 3.1
- Type narrowing
- [Bug] Custom formats not working for objects
- fs-routes is using a vulnerable version of glob HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from open-api.