Autorest: Generate Models Only

Created on 12 Feb 2018  路  3Comments  路  Source: Azure/autorest

I have been looking for a setting but have been unable to find it so far. Is it currently possible to generate models only for this?

For reference, in the petstore sample, I only want to generate the following files:
image

Most helpful comment

You can do that by putting a few things in configuration:

make a readme.md configuration file like this:

~~~ markdown

Scenario: Models Only

see https://aka.ms/autorest

input-file: petstore.json

directive:
  # removes all the operations from the code generation (leaves behind empty serviceclient though)
  - from: "code-model-v1" 
    where: $.operations[*]
    transform: return undefined

  # removes all the rest of the files that we don't want. (ie, if they say "using Models") 
  - from: source-file-csharp
    where: $
    transform: if ($.includes("using Models;")) return "";

~~~

All 3 comments

You can do that by putting a few things in configuration:

make a readme.md configuration file like this:

~~~ markdown

Scenario: Models Only

see https://aka.ms/autorest

input-file: petstore.json

directive:
  # removes all the operations from the code generation (leaves behind empty serviceclient though)
  - from: "code-model-v1" 
    where: $.operations[*]
    transform: return undefined

  # removes all the rest of the files that we don't want. (ie, if they say "using Models") 
  - from: source-file-csharp
    where: $
    transform: if ($.includes("using Models;")) return "";

~~~

Confirmed this does exactly what I had asked, so I'll close this. I'm curious if you see this being a common scenario? I'd imagine many people having their own libs that probably call external APIs (maybe with fallbacks, retries, circuit breakers, etc) that accept plain models as inputs. Also, the answer is very C# specific. It would be nice to have a more language agnostic solution

I'm receiving the following error when I use this.

FATAL: csharp/cm/transform - FAILED
FATAL: Error: Error retrieving '$.operations[16]' (Error: Trying to retrieve item '16' from sequence with '15' items (index out of bounds))
Process() cancelled due to exception : Error retrieving '$.operations[16]' (Error: Trying to retrieve item '16' from sequence with '15' items (index out of bounds))
  Error: Error retrieving '$.operations[16]' (Error: Trying to retrieve item '16' from sequence with '15' items (index out of bounds))
Was this page helpful?
0 / 5 - 0 ratings