Skip to content

Refactor compile_to_openapi30 function #7

Description

@mrshll1001

The schema tools support generating OpenAPI 3.0 from an OpenAPI 3.1 openapi.json file, with the purposes of being compatible with SwaggerUI pages. This is provided by a function starting on L443, called compile_to_openapi30().

Currently this function takes two parameters: schemas_path docs_dir, finds the openapi.json file, generates the compiled 3.0 version, and writes it to a hard-coded path underneath docs_dir.

I think it would be better if this function behaved more like the schemas_to_datapackage CLI command / function, where it simply returns the output as a string rather than having the side-effect of creating the file. Instead of a schemas_path parameter, it should take a path directly to the openapi.json file that it's refactoring.

We could then:

  • expose the command via the CLI interface, allowing people to generate the file and pipe it to a file, or as input to another program.
  • support Profile documentation with this functionality.

For the latter, it's clear that this was intended because a call to this function is commented out on L593 within the profile_all() function.

This would also require some light refactoring some other functions where a call to compile_to_openapi30() is made, such as docs_all(), but would make the code more modular and sustainable as well as providing more functionality to end-users.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions