Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different behaviour deppending on the RPC's name #57

Closed
Albertojuanse opened this issue Sep 6, 2022 · 4 comments
Closed

Different behaviour deppending on the RPC's name #57

Albertojuanse opened this issue Sep 6, 2022 · 4 comments
Assignees

Comments

@Albertojuanse
Copy link

Albertojuanse commented Sep 6, 2022

Hi @bartoszm,
we have found that, when processing a YANG with RPC, it creates or not some definitions depending on its name.

Version

swagger-generator-cli-1.1.14.jar on Ubuntu 20.04

Example

Using the following YANG

module objects {

  yang-version "1.1";
  namespace "urn:objects";
  prefix "obje";

  grouping id_1 {
    leaf id_1 {
      type "string";
    }
  }

  grouping id_2 {
    leaf id_2 {
      type "string";
    }
  }

  rpc create-object {
    input {
      uses id_1;
      uses id_2;
    }
    output {
    }
  }

  rpc update-object {
    input {
      uses id_1;
      uses id_2;
    }
    output {
    }
  }
}

it creates the following Swagger, with createobject.Input defined but updateobject.Input not defined.

---
swagger: "2.0"
info:
  description: "objects API generated from yang definitions"
  version: "1.0"
  title: "objects API"
host: "localhost:1234"
consumes:
- "application/yang-data+json"
produces:
- "application/yang-data+json"
paths:
  /operations/create-object/:
    post:
      tags:
      - "objects"
      summary: "operates on objects.CreateObject"
      description: "operates on objects.CreateObject"
      parameters:
      - in: "body"
        name: "objects.createobject.Input.body-param"
        required: false
        schema:
          properties:
            input:
              $ref: "#/definitions/objects.createobject.Input"
      responses:
        201:
          description: "No response"
        400:
          description: "Internal error"
  /operations/update-object/:
    post:
      tags:
      - "objects"
      summary: "operates on objects.UpdateObject"
      description: "operates on objects.UpdateObject"
      parameters:
      - in: "body"
        name: "objects.updateobject.Input.body-param"
        required: false
        schema:
          properties:
            input:
              $ref: "#/definitions/objects.updateobject.Input"
      responses:
        201:
          description: "No response"
        400:
          description: "Internal error"
definitions:
  objects.Id1:
    type: "object"
    properties:
      id_1:
        type: "string"
  objects.Id2:
    type: "object"
    properties:
      id_2:
        type: "string"
  objects.createobject.Input:
    allOf:
    - $ref: "#/definitions/objects.Id1"
    - $ref: "#/definitions/objects.Id2"

The terminal output is the following

2022-09-06 18:33:02,226 [main] INFO  c.mrv.yangtools.common.ContextHelper - adding 
2022-09-06 18:33:02,293 [main] INFO  c.mrv.yangtools.common.SchemaBuilder - Inspecting all defined yangs [objects.yang]
2022-09-06 18:33:02,596 [main] INFO  com.mrv.yangtools.codegen.main.Main - Modules found in the  objects
2022-09-06 18:33:02,668 [main] INFO  c.m.y.codegen.SwaggerGenerator - Generating swagger for yang modules: [objects]
2022-09-06 18:33:02,676 [main] WARN  c.m.y.c.i.OptimizingDataObjectBuilder - no child found with name (urn:objects?revision=1970-01-01)id_2
2022-09-06 18:33:02,679 [main] WARN  c.m.y.c.i.OptimizingDataObjectBuilder - no child found with name (urn:objects?revision=1970-01-01)id_1
2022-09-06 18:33:02,681 [main] WARN  c.m.y.c.i.OptimizingDataObjectBuilder - Multiple inheritance for (urn:objects?revision=1970-01-01)input
2022-09-06 18:33:02,683 [main] WARN  c.m.y.c.i.OptimizingDataObjectBuilder - Multiple inheritance for (urn:objects?revision=1970-01-01)input

Then, we change the name of the RPC with no definition (run instead of update) in the RPC name.

module objects {

  yang-version "1.1";
  namespace "urn:objects";
  prefix "obje";

  grouping id_1 {
    leaf id_1 {
      type "string";
    }
  }

  grouping id_2 {
    leaf id_2 {
      type "string";
    }
  }

  rpc create-object {
    input {
      uses id_1;
      uses id_2;
    }
    output {
    }
  }

  rpc run-object {
    input {
      uses id_1;
      uses id_2;
    }
    output {
    }
  }
}
2022-09-06 18:35:01,716 [main] INFO  c.mrv.yangtools.common.ContextHelper - adding 
2022-09-06 18:35:01,782 [main] INFO  c.mrv.yangtools.common.SchemaBuilder - Inspecting all defined yangs [objects.yang]
2022-09-06 18:35:02,115 [main] INFO  com.mrv.yangtools.codegen.main.Main - Modules found in the  are objects
2022-09-06 18:35:02,178 [main] INFO  c.m.y.codegen.SwaggerGenerator - Generating swagger for yang modules: [objects]
2022-09-06 18:35:02,186 [main] WARN  c.m.y.c.i.OptimizingDataObjectBuilder - no child found with name (urn:objects?revision=1970-01-01)id_2
2022-09-06 18:35:02,189 [main] WARN  c.m.y.c.i.OptimizingDataObjectBuilder - no child found with name (urn:objects?revision=1970-01-01)id_1
2022-09-06 18:35:02,191 [main] WARN  c.m.y.c.i.OptimizingDataObjectBuilder - Multiple inheritance for (urn:objects?revision=1970-01-01)input
2022-09-06 18:35:02,193 [main] WARN  c.m.y.c.i.OptimizingDataObjectBuilder - Multiple inheritance for (urn:objects?revision=1970-01-01)input

And, now, the defined object is runobject.Input but no createobject.Input, the one which worked before.

---
swagger: "2.0"
info:
  description: "objects API generated from yang definitions"
  version: "1.0"
  title: "objects API"
host: "localhost:1234"
consumes:
- "application/yang-data+json"
produces:
- "application/yang-data+json"
paths:
  /operations/create-object/:
    post:
      tags:
      - "objects"
      summary: "operates on objects.CreateObject"
      description: "operates on objects.CreateObject"
      parameters:
      - in: "body"
        name: "objects.createobject.Input.body-param"
        required: false
        schema:
          properties:
            input:
              $ref: "#/definitions/objects.createobject.Input"
      responses:
        201:
          description: "No response"
        400:
          description: "Internal error"
  /operations/run-object/:
    post:
      tags:
      - "objects"
      summary: "operates on objects.RunObject"
      description: "operates on objects.RunObject"
      parameters:
      - in: "body"
        name: "objects.runobject.Input.body-param"
        required: false
        schema:
          properties:
            input:
              $ref: "#/definitions/objects.runobject.Input"
      responses:
        201:
          description: "No response"
        400:
          description: "Internal error"
definitions:
  objects.Id1:
    type: "object"
    properties:
      id_1:
        type: "string"
  objects.Id2:
    type: "object"
    properties:
      id_2:
        type: "string"
  objects.runobject.Input:
    allOf:
    - $ref: "#/definitions/objects.Id1"
    - $ref: "#/definitions/objects.Id2"
    - 

One can try several combinations with different behaviour. Do you know what it is going on?
Thank you!

@bartoszm
Copy link
Collaborator

I have confirmed this issue. Will come up with a solution soon

@Albertojuanse
Copy link
Author

Thank you, Bartosz,
I appreciate that.

bartoszm added a commit that referenced this issue Sep 13, 2022
bartoszm added a commit that referenced this issue Sep 13, 2022
bartoszm added a commit that referenced this issue Sep 13, 2022
@bartoszm
Copy link
Collaborator

I have released a new version of the tool that should solve your issue: https://github.com/bartoszm/yang2swagger/releases/tag/1.2
Please reopen if I am mistaken.

@bartoszm bartoszm self-assigned this Sep 13, 2022
@Albertojuanse
Copy link
Author

Hi Bartosz,

I am afraid we are still seeing the same behaviour, without any change. We have tested the .jar that you released with the same YANG example I copied above, and it does the same.

I have checked the JAVA versions, just in case, and we tested it with openjdk 11.0.16 2022-07-19 and java version "1.8.0_201".

Also, we could see in one commit that you added the option -reuse-groupings, so we also tried it and the trace says "-reuse-groupings" is not a valid option.

What has been indeed fixed is that, in operations created from RFCs, "#/definitions/" was previously missing in the references. It's a bug that we hadn't reported yet, but we've seen that you've fixed it already. However, the behaviour is the same with the missing objects ".Input".

Do you need more information?

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants