Skip to content

Models: Writing Node reorders Operations #643

Open
@zaiddabaeen

Description

@zaiddabaeen

When saving an OpenAPI spec using ApiCurio, the order of operations is forced. This is because of how writePathItem is implemented, where it checks if the node has "get", writes it, then "put"... then "post"... As seen in the generated ts file OpenApi31ModelWriter.ts:


    public writePathItem(node: OpenApi31PathItem, json: object) {
        if (node == null){
            return;
        }
        JsonUtil.setStringProperty(json, "$ref", node.get$ref());
        JsonUtil.setStringProperty(json, "summary", node.getSummary());
        JsonUtil.setStringProperty(json, "description", node.getDescription());
        {
            if (node.getGet() != null){
                const object: object = JsonUtil.objectNode();
                this.writeOperation(<OpenApi31Operation><any>node.getGet(), object);
                JsonUtil.setObjectProperty(json, "get", object);
            }
        };
        {
            if (node.getPut() != null){
                const object: object = JsonUtil.objectNode();
                this.writeOperation(<OpenApi31Operation><any>node.getPut(), object);
                JsonUtil.setObjectProperty(json, "put", object);
            }
        };
        {
            if (node.getPost() != null){
                const object: object = JsonUtil.objectNode();
                this.writeOperation(<OpenApi31Operation><any>node.getPost(), object);
                JsonUtil.setObjectProperty(json, "post", object);
            }
        };
        {
            if (node.getDelete() != null){
                const object: object = JsonUtil.objectNode();
                this.writeOperation(<OpenApi31Operation><any>node.getDelete(), object);
                JsonUtil.setObjectProperty(json, "delete", object);
            }
        };
...

I understand that all of the models are generated from resources/specs/openapi, which makes it really hard to modify how this works.

Is there a way to override this function's implementation with one that iterates over the key/values and writes them, so no order is enforced?

Would be happy to write a PR if there's a way to do this.

Motivation:
Some of our users of the editor wish to follow the the example of larger companies in how the operations are ordered in their API references, where creating resources goes first, then reading them, them updating them, then deleting them - as they report that this is the natural way of reading an API spec, as to read resources, they should be created first.

Related: Apicurio/apicurio-studio#1677

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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