yonaskolb / SwagGen

OpenAPI/Swagger 3.0 Parser and Swift code generator
MIT License
625 stars 147 forks source link

TemplateFiles - Context Options #169

Closed JacobJerrell closed 5 years ago

JacobJerrell commented 5 years ago

@yonaskolb I've been having an issue with the following line from the readme.md regarding the template.yml file;

Note that properties in the template options field can be used here

The models my team uses are somewhat unique and I essentially need to generate 2 files for each schema; a resource model, and a wrapper. I need the resource models to have a suffix but not the wrappers. I'm trying to implement it like this:

templateFiles:
  - path: Sources/Dto.swift
    context: schemas
    modelSuffix: Dto # applied to model classes
    destination: "Sources/Dtos/{{ type }}.swift"

I've played with the positioning of the modelSuffix option in many different ways beneath context, but this is the only one that doesn't result in an error at runtime. But it still doesn't add a suffix to the files. I can't find any examples of options being used in templateFiles->context

JacobJerrell commented 5 years ago

Still had no success in getting this to work. But since the context is available in this file, I just added {% if not enum %}Dto{% endif %} to the destination and all my troubles are solved

yonaskolb commented 5 years ago

Glad you got it resolved. Yeah there’s no support for file specific options like that, you would just have to add it to the file template itself, as you’ve done.

Closing this for now, let me know if you have any other issues