Comments (4)
Hmmm. Don't know why github ate my uploads... but I'll see if I can find them or re-create them later today.
from createapi.
Hey @mgrider, sorry for missing this. The links to the examples seem to be broken, is it possible for you to share the output again?
You can use <details>
to add the code in the comment, like the example below:
<details>
<summary>cleaned-openapi.yaml</summary>
<!-- ```yaml -->
<!-- Add the code here (without the html comments) -->
<!-- ``` -->
</details>
For example:
cleaned-openapi.yaml
# schema
from createapi.
I think this basically happens any time a path has a trailing slash in the yaml spec, for example:
paths:
/api/lists/:
This will result in a generated Paths
extension containing:
public·static·var·lists:·Lists·{
Lists(path:·"/api/lists")
}
The command I'm using looks like this:
$ mint run CreateAPI create-api generate api.yaml --package APIPackage -c -s --output build
Here's a full-spec example that exhibits this behavior:
api.yaml
openapi: 3.0.2
info:
title: Mobile API
version: 1.0.0
description: Private API for Mobile Apps
paths:
/api/lists/:
get:
operationId: listLists
description: ''
parameters:
- name: limit
required: false
in: query
description: Number of results to return per page.
schema:
type: integer
- name: offset
required: false
in: query
description: The initial index from which to return the results.
schema:
type: integer
responses:
'200':
content:
application/json:
schema:
type: object
properties:
count:
type: integer
example: 123
next:
type: string
nullable: true
format: uri
example: http://api.example.org/accounts/?offset=400&limit=100
previous:
type: string
nullable: true
format: uri
example: http://api.example.org/accounts/?offset=200&limit=100
results:
type: array
items:
$ref: '#/components/schemas/List'
description: ''
tags:
- api
/api/lists/{url_locator}/:
get:
operationId: retrieveList
description: ''
parameters:
- name: url_locator
in: path
required: true
description: ''
schema:
type: string
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/ListDetail'
description: ''
tags:
- api
/api/token-auth/:
post:
operationId: createAuthToken
description: ''
parameters: []
requestBody:
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/AuthToken'
multipart/form-data:
schema:
$ref: '#/components/schemas/AuthToken'
application/json:
schema:
$ref: '#/components/schemas/AuthToken'
responses:
'201':
content:
application/json:
schema:
$ref: '#/components/schemas/AuthToken'
description: ''
tags:
- api
components:
schemas:
List:
type: object
properties:
url_locator:
type: string
maxLength: 100
user:
type: object
properties:
first_name:
type: string
maxLength: 150
last_name:
type: string
maxLength: 150
userprofile:
type: object
properties:
url_locator:
type: string
maxLength: 100
avatar:
type: object
properties:
url:
type: string
readOnly: true
readOnly: true
required:
- url_locator
readOnly: true
readOnly: true
title:
type: string
description: Name your list
maxLength: 255
description:
type: string
nullable: true
description: Why are you making this list? Who should look at it? (optional)
modified:
type: string
format: date-time
readOnly: true
modified_date:
type: string
readOnly: true
modified_date_short:
type: string
readOnly: true
modified_humanized_delta:
type: string
readOnly: true
created:
type: string
format: date-time
readOnly: true
privacy_level:
enum:
- 0
- 1
- 2
type: integer
minimum: -2147483648
maximum: 2147483647
privacy_level_display:
type: string
readOnly: true
search_visibility:
enum:
- 2
- 1
- 0
type: integer
minimum: -2147483648
maximum: 2147483647
required:
- url_locator
- title
ListDetail:
type: object
properties:
url_locator:
type: string
maxLength: 100
user:
type: object
properties:
first_name:
type: string
maxLength: 150
last_name:
type: string
maxLength: 150
userprofile:
type: object
properties:
url_locator:
type: string
maxLength: 100
avatar:
type: object
properties:
url:
type: string
readOnly: true
readOnly: true
required:
- url_locator
readOnly: true
readOnly: true
title:
type: string
description: Name your list
maxLength: 255
description:
type: string
nullable: true
description: Why are you making this list? Who should look at it? (optional)
modified:
type: string
format: date-time
readOnly: true
modified_date:
type: string
readOnly: true
modified_date_short:
type: string
readOnly: true
modified_humanized_delta:
type: string
readOnly: true
created:
type: string
format: date-time
readOnly: true
privacy_level:
enum:
- 0
- 1
- 2
type: integer
minimum: -2147483648
maximum: 2147483647
privacy_level_display:
type: string
readOnly: true
search_visibility:
enum:
- 2
- 1
- 0
type: integer
minimum: -2147483648
maximum: 2147483647
is_archive_list:
type: string
readOnly: true
is_child_list:
type: string
readOnly: true
is_shared:
type: string
readOnly: true
is_private:
type: string
readOnly: true
is_public:
type: string
readOnly: true
required:
- url_locator
- title
AuthToken:
type: object
properties:
username:
type: string
writeOnly: true
password:
type: string
writeOnly: true
token:
type: string
readOnly: true
required:
- username
- password
...and one of the resulting swift files:
build/APIPackage/Sources/Paths/PathsAPILists.swift
// Generated by Create API
// https://github.com/CreateAPI/CreateAPI
//
// swiftlint:disable all
import Foundation
import Get
import URLQueryEncoder
extension Paths {
public static var lists: Lists {
Lists(path: "/api/lists")
}
public struct Lists {
/// Path: `/api/lists`
public let path: String
public func get(limit: Int? = nil, offset: Int? = nil) -> Request<GetResponse> {
.get(path, query: makeGetQuery(limit, offset))
}
public struct GetResponse: Decodable {
/// Example: 123
public var count: Int?
/// Example: "http://api.example.org/accounts/?offset=400&limit=100"
public var next: URL?
/// Example: "http://api.example.org/accounts/?offset=200&limit=100"
public var previous: URL?
public var results: [APIPackage.List]?
public init(count: Int? = nil, next: URL? = nil, previous: URL? = nil, results: [APIPackage.List]? = nil) {
self.count = count
self.next = next
self.previous = previous
self.results = results
}
}
private func makeGetQuery(_ limit: Int?, _ offset: Int?) -> [(String, String?)] {
let encoder = URLQueryEncoder()
encoder.encode(limit, forKey: "limit")
encoder.encode(offset, forKey: "offset")
return encoder.items
}
}
}
Worth noting that after some discussion, we decided to remove the trailing slashes on the server-side for my current project, and this is no longer an issue. But for a few iterations, I was manually editing all the resulting files to re-add the trailing slashes to the URLs.
from createapi.
Ahh thanks for that, I see what you are saying! In fact, I can see it in our existing test fixtures:
CreateAPI/Tests/CreateAPITests/Expected/cookpad/Sources/Paths.swift
Lines 10 to 12 in 36e7838
I dug into it very quickly, and it seems like the root of this issue lies with OpenAPIKit:
OpenAPI.Path
holds its data as an array of components
that seems to discard knowledge of the leading and trailing /
's. I think if that is patched upstream, it should just work in CreateAPI though 🤞
This is useful to know but I am going to close this. I guess its not that important now, but if you do need this resolving then please open a new ticket in OpenAPIKit.
Thanks for taking the time to find the example again!
from createapi.
Related Issues (20)
- Request uses incorrect body instead of asQuery HOT 1
- Schema component named `Request` generates ambiguous code HOT 4
- `AnyJSON` type included unexpectedly
- Adjust behaviour of `includeDefaultValues` to favour "correctness" by default HOT 1
- integer backed enums are stored as integer properties as opposed to enums HOT 1
- generated package depends on an old version of Get HOT 3
- Tagged type for IDs? HOT 2
- FR: Entity replace substring, instead of naming template HOT 1
- Equatable conformance HOT 1
- Parameters to be passed in headers are ignored during API generation
- Acronyms change property names without changing corresponding CodingKeys
- Deduplicate identical structs/classes
- Add option to separate GET from POST and PATCH requests and only include Decodable respectively Encodable conformance
- Option for treating non-optional enum with only one case as a static value
- `type` definition in OpenAPI spec is overridden by `format` value
- Is there a way to generate `CodingKeys`?
- How to wildcard rules in include and exclude paths
- Use `Swift Syntax`
- Make 'Request' type name configurable HOT 1
- Will OpenAPI schema v3.1.0 be supported?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from createapi.