Swagger-codegen: Different namespaces for different models

Created on 3 Oct 2016  路  8Comments  路  Source: swagger-api/swagger-codegen

How I can separate various model into various folders and namespaces? Should I use some options during generation client? I'm interesting about php-client.

PHP Question

All 8 comments

See modelPackage in config options.

@cbornet , where I can get usage example of this option?

See the README. You can either use it by command line

swagger-codegen-cli generate
               ...
                [--library <library>] [--model-package <model package>]
                ...

Or by including a json config file (option -c)

@serezha93 FYI. here are the full list of options for PHP:

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l php

CONFIG OPTIONS
    sortParamsByRequiredFlag
        Sort method arguments to place required parameters before optional parameters. (Default: true)

    ensureUniqueParams
        Whether to ensure parameter names are unique in an operation (rename parameters that are not). (Default: true)

    modelPackage
        package for generated models

    apiPackage
        package for generated api classes

    variableNamingConvention
        naming convention of variable name, e.g. camelCase. (Default: snake_case)

    invokerPackage
        The main namespace to use for all classes. e.g. Yay\Pets

    packagePath
        The main package name for classes. e.g. GeneratedPetstore

    srcBasePath
        The directory under packagePath to serve as source root.

    composerVendorName
        The vendor name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name. e.g. yaypets. IMPORTANT NOTE (2016/03): composerVendorName will be deprecated and replaced by gitUserId in the next swagger-codegen release

    gitUserId
        Git user ID, e.g. swagger-api.

    composerProjectName
        The project name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name. e.g. petstore-client. IMPORTANT NOTE (2016/03): composerProjectName will be deprecated and replaced by gitRepoId in the next swagger-codegen release

    gitRepoId
        Git repo ID, e.g. swagger-codegen.

    artifactVersion
        The version to use in the composer package version field. e.g. 1.2.3

    hideGenerationTimestamp
        hides the timestamp when files were generated (Default: true)

https://github.com/swagger-api/swagger-codegen#customizing-the-generator is a good starting point on how to use these options via a config file (json)

As I understood property modelPackage set default value for root namespace, but I can't change namespaces depend by its property, isn't it? For example, I want create folders for method's submethods.

Based on what you want, it's still technically possible by customizing the PHP client generator and the templates

How do i do this?

Swagger\Client\Configuration::getDefaultConfiguration()->setDebug(true)
i want
ProjectName\Client\Configuration::getDefaultConfiguration()->setDebug(true)

@kgrosvenor Have you tried the following options to customize the PHP client?

    invokerPackage
        The main namespace to use for all classes. e.g. Yay\Pets

    packagePath
        The main package name for classes. e.g. GeneratedPetstore

Ref: java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l php

Was this page helpful?
0 / 5 - 0 ratings