swagger-api / swagger-api/swagger-codegen

[Swift4] Should generate validation code from specs for requests

Open
#7,019 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I use swagger-codegen to generate an API for Swift4.

The Swagger YAML file contains as well additional information. e.g. minLength, maxLength
Issue: I cannot find this information (minLength,maxLength) in the generated code for Swift 4 requests.

Swagger-codegen version

snapshots:
3.0.0 = tried with swagger-codegen-cli-3.0.0-20171114.064241-7.jar
2.3.0 = and with swagger-codegen-cli-2.3.0-20171121.153419-270.jar

Swagger declaration file content or url
  PaymentRequest:
    properties:
      amount:
        description: Payment amount 
        type: number
        format: double
      toBSB:
        description: Branch ID of payee account 
        type: string
        format: '^$|^\d{6}$'
      toAccount:
        description: Account number of payee account
        type: string
        maxLength: 16
Command line used for generation

java -jar /Documents/Development/Tools/swagger-codegen-cli-2.3.0-20171121.153419-270.jar generate -i /Documents/Development/Payments.yaml -l swift4 -o /tmp/swg1

Steps to reproduce

just generate command as above

Related issues/PRs

not specifically for Swift4 but others are also facing the same issue in their areas
https://github.com/swagger-api/swagger-codegen/issues/6410
https://github.com/swagger-api/swagger-codegen/issues/2304

Suggest a fix/enhancement

Can you make it so that the when creating the Request there is a validate method that will check as per the given rules in the YAML.. so that this is executed before the request goes out from the client?

Additionally if these can be separated from the request, then we can extend it with any other rules we'd like to implement.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the supplied swagger-codegen generate command with the PaymentRequest YAML and inspect the generated Swift4 request models. Trace how minLength and maxLength are handled during generation; done means generated requests validate those constraints before sending, with an extensible path for additional rules.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.