You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hi i am trying to validate an openapi 3 file, json format,
using other tools i got
{"errors":[{"code":400,"message":"Malformed OAS3 document: attribute components.schemas.Schema name ResponsePayloadByte[] doesn't adhere to regular expression ^[a-zA-Z0-9\.\-_]+$"}
should conform to rfc3968 at instance /paths/~1pdf~1documents~1{imageId}/get/responses/200/content/*~1*/schema/$ref (schema #/definitions/Reference/patternProperties/^\$ref$/format)
It complains about this invalid ref: "$ref": "#/components/schemas/ResponsePayloadByte[]".
This corresponds to the error you expect. I guess the other tools inlines ResponsePayloadByte[] and then complains about its name.
it reports a few more errors but they are all related to the error above. I should probably filter out the other errors.
Here is the code I'm using (it is kotlin test code but hopefully easy enough to understand)
importio.kotest.core.spec.style.StringSpecimportio.openapiprocessor.jackson.JacksonConverterimportio.openapiprocessor.jsonschema.reader.UriReaderimportio.openapiprocessor.jsonschema.schema.DocumentLoaderimportio.openapiprocessor.jsonschema.schema.DocumentStoreimportio.openapiprocessor.jsonschema.schema.SchemaStoreimportio.openapiprocessor.jsonschema.validator.Validatorimportio.openapiprocessor.jsonschema.validator.ValidatorSettingsclassValidateSpec: StringSpec({
"validate openapi" {
val documents = DocumentStore()
val loader = DocumentLoader(
UriReader(),
JacksonConverter()
)
val parser = OpenApiParser(documents, loader)
val result = parser.parse("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/v30/openapi-95.json")
val store = SchemaStore(loader)
store.registerDraft4()
val validator = Validator()
val valid = result.validate(validator, store)
val errors = result.validationErrors
val builder = ValidationErrorTextBuilder()
for (error in errors) {
println(builder.getText(error))
}
}
)}
Yes, strange indeed. Using your code works for me. With or without the register using your example api.
One difference is that I'm using JacksonConverter() as I don't know what json and yml is in your snippet. But I would expect an exception if something goes wrong there.
If you can create a minimal working project that reproduces the issue I could check what is going.
Activity
hauner commentedon Jun 7, 2024
Yes, I think it should report that error. I will look at it.
hauner commentedon Jun 8, 2024
For me validating your file I get
should conform to rfc3968 at instance /paths/~1pdf~1documents~1{imageId}/get/responses/200/content/*~1*/schema/$ref (schema #/definitions/Reference/patternProperties/^\$ref$/format)It complains about this invalid ref:
"$ref": "#/components/schemas/ResponsePayloadByte[]".This corresponds to the error you expect. I guess the other tools inlines
ResponsePayloadByte[]and then complains about its name.it reports a few more errors but they are all related to the error above. I should probably filter out the other errors.
Here is the code I'm using (it is kotlin test code but hopefully easy enough to understand)
matteo-rama commentedon Jun 10, 2024
what happen if you don't use "registerDraft4"?
if i don't use "registerdraft4" i see no error, still it shouldn't validate if i understand correctly?
hauner commentedon Jun 11, 2024
Yes. The register just avoids a network call.
It adds the draft-4 json schema from the jar resources. Without the register it will download the json schema.
matteo-rama commentedon Jun 11, 2024
i am sorry to bother you again...
but if the enable draf4 just avoid network calls, then, why this snippet validate?
strangely if i remove the comment // store.registerDraft4 i got the exception
hauner commentedon Jun 12, 2024
Yes, strange indeed. Using your code works for me. With or without the register using your example api.
One difference is that I'm using
JacksonConverter()as I don't know whatjsonandymlis in your snippet. But I would expect an exception if something goes wrong there.If you can create a minimal working project that reproduces the issue I could check what is going.