autorest icon indicating copy to clipboard operation
autorest copied to clipboard

Directive - Add Properties

Open SMITTY-94 opened this issue 4 years ago • 5 comments

I'm currently trying to generate the C-Sharp SDK but need to add a property to our Swagger. Is there a way to do this with using directives? I have looked over plenty of documentation but can only find operations related to modifying or removing properties.

Example:

The line with the red arrow does not exist in the swagger and I need to add it. image

Thank you for any help!

SMITTY-94 avatar Sep 07 '22 18:09 SMITTY-94

Hey @AndrewCS149 Something like that?

directive:
  from: swagger-document
  where: "$.definitions.Foo.properties"
  transform: |
    $.myProp = {...}

timotheeguerin avatar Sep 07 '22 22:09 timotheeguerin

Hey @timotheeguerin. Thanks for the response. So in my case, would it look similar to this? I can't seem to pin down the exact syntax

directive: 
  - from: swagger.json
    where: $definitions.AssignmentReportProperties.properties
    transform: |
      $.format = duration

SMITTY-94 avatar Sep 08 '22 19:09 SMITTY-94

Oh sorry thought you meant an full openapi3 property. If you just want to update a json property that looks about good expect duration must be in quotes "duration".

The content of transform is just Javascript code.

Your directive should be

  - from: swagger.json
    where: $definitions.AssignmentReportProperties.properties.duration
    transform: |
      $.format = "duration"

timotheeguerin avatar Sep 08 '22 19:09 timotheeguerin

heck yeah that worked @timotheeguerin! Thanks so much!

SMITTY-94 avatar Sep 08 '22 20:09 SMITTY-94

np

timotheeguerin avatar Sep 08 '22 20:09 timotheeguerin