parser-go icon indicating copy to clipboard operation
parser-go copied to clipboard

Create AsyncAPI/OpenAPI schema parser

Open fmvilas opened this issue 6 years ago • 10 comments

Create AsyncAPI/OpenAPI schema to JSON Schema Draft 07 converter. It should have a single method as follows:

.Parse(schema []byte) (result json.RawMessage, error)

result must be a JSON Schema Draft 07-compatible of type json.RawMessage.

Implementation suggestion

We could create this library separated from the parser so other projects can benefit from it too.

Differences between OpenAPI/AsyncAPI schemas and JSON Schema Draft 07 schemas

  • nullable: Must translate to type array, e.g., "type": ["string", null]
  • discriminator: Must be removed or ignored, i.e., it must not be included in the JSON Schema Draft 07 schema. There's not strong opinion here, so if you prefer to just keep it, it would be just fine too.
  • xml: Should remain the same as in OpenAPI schema.
  • externalDocs: Should remain the same as in OpenAPI schema.
  • example: Should be renamed to examples and be of type array.
  • deprecated: Should remain the same as in OpenAPI schema.
  • readOnly: Should remain the same as in OpenAPI schema.
  • writeOnly: Should remain the same as in OpenAPI schema.

References

  • https://github.com/mikunn/openapi-schema-to-json-schema
  • [ ] :bug: Unit tests
  • [ ] :books: Documentation

fmvilas avatar Mar 06 '19 16:03 fmvilas

I'd like to work on this if possible.

RobertDiebels avatar Mar 14 '19 11:03 RobertDiebels

Absolutely! Just want to remark that this is just for schemas, not the whole OpenAPI/AsyncAPI document.

fmvilas avatar Mar 14 '19 12:03 fmvilas

@fmvilas Great :D ! Alright, I'll have a look at the repo you linked this weekend. If I have any questions I'll let you know. Also, could you assign the issue to me?

RobertDiebels avatar Mar 15 '19 08:03 RobertDiebels

Done!

fmvilas avatar Mar 16 '19 09:03 fmvilas

@fmvilas I've read the documentation in the repository you linked. Am I right in concluding the aim is to parse an AsyncAPI-spec and convert it to a JSON-schema so other software can use the JSON-schema to validate incoming/outgoing messages?

RobertDiebels avatar Mar 17 '19 16:03 RobertDiebels

You're totally right :)

This way we can leverage existing JSON Schema tooling, which is a lot.

fmvilas avatar Mar 17 '19 17:03 fmvilas

@fmvilas I might take a bit longer to get this fixed. I'm on developing on Windows and I'm encountering some issues when compiling the code-base to C. I'm currently looking for a solution that doesn't involve to much hassle.

RobertDiebels avatar Mar 23 '19 11:03 RobertDiebels

I'd forget about the parser and would do it as a separate library/repo. You don't need the rest of the parser nor compiling it to C to make it work.

Make it simpler and go for a simple Go library that takes a byte array and returns a json.RawMessage and error:

func Parse(protobufSchema []byte) (json.RawMessage, error) {
  ...
}

See more here: https://github.com/asyncapi/parser/blob/master/TECHNICAL%20PROPOSAL.md#api-of-a-specific-schema-parser-instance-eg-protobuf-schema-parser

fmvilas avatar Mar 23 '19 11:03 fmvilas

This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:

github-actions[bot] avatar Mar 12 '20 00:03 github-actions[bot]