-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make moduleObject.mustache confirms to JSONEncodable. #11202
Changes from 2 commits
09dacc7
fc433db
aae8e6d
1c06b4d
7836e27
e55c757
ebd7d01
d855a09
4929d5b
f4da07a
7c1a144
8b1529f
6ec206b
5a1661b
7acc1fb
51fe33f
672df35
8962b8b
235b824
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,3 +206,13 @@ extension Set: RequestDecodable where Element: Content { | |
extension Set: Content where Element: Content { } | ||
|
||
extension AnyCodable: Content {}{{/useVapor}} | ||
|
||
extension JSONEncodable where Self: Encodable { | ||
func encodeToJSON() -> Any { | ||
let encoder = JSONEncoder() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @0x0c here instead of creating a new JSONEncoder, please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done with 1c06b4d |
||
guard let data = try? encoder.encode(self) else { | ||
fatalError("Could not encode to json: \(self)") | ||
} | ||
return data.base64EncodedString(options: Data.Base64EncodingOptions()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @0x0c I'm a little worried about this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated line 216 so please check 7836e27 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{{^objcCompatible}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} {{#useClasses}}final class{{/useClasses}}{{^useClasses}}struct{{/useClasses}} {{{classname}}}: {{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable{{/useVapor}}{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}} { | ||
{{/objcCompatible}}{{#objcCompatible}}@objc {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class {{classname}}: NSObject, Codable { | ||
{{^objcCompatible}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} {{#useClasses}}final class{{/useClasses}}{{^useClasses}}struct{{/useClasses}} {{{classname}}}: {{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable{{/useVapor}}{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}}, JSONEncodable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @0x0c to make the CI pass, could you please update this line to be
Because when using Vapor, we can't make the model conform to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done with aae8e6d |
||
{{/objcCompatible}}{{#objcCompatible}}@objc {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class {{classname}}: NSObject, Codable, JSONEncodable { | ||
{{/objcCompatible}} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please also add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{{#allVars}} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: test | ||
version: '1.0' | ||
servers: | ||
- url: 'http://localhost:3000' | ||
paths: | ||
/postModel: | ||
post: | ||
summary: Create New User | ||
operationId: post-user | ||
responses: | ||
'200': | ||
description: User Created | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/User' | ||
examples: {} | ||
'400': | ||
description: Missing Required Information | ||
description: Create a new user. | ||
requestBody: | ||
content: | ||
multipart/form-data: | ||
schema: | ||
$ref: '#/components/schemas/Request' | ||
parameters: [] | ||
components: | ||
schemas: | ||
User: | ||
title: User | ||
type: object | ||
description: '' | ||
x-examples: {} | ||
properties: | ||
integerValue: | ||
type: integer | ||
Request: | ||
title: Request | ||
type: object | ||
properties: | ||
user1: | ||
$ref: '#/components/schemas/User' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0x0c could you please move this entire block of code to line 63, so that it's not generated when using vapor, for CI to pass?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with ebd7d01