forked from grpc-ecosystem/grpc-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added pathenum proto for an externally imported enum example and verification Added enum_helper.go to handle the lack of enum support in the swagger-codegen-cli 2.2.2 for Go, see swagger-api/swagger-codegen#5635
- Loading branch information
Marcus Rosén
committed
Aug 28, 2018
1 parent
ab4f1a7
commit 8053abb
Showing
16 changed files
with
588 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package abe | ||
|
||
import ( | ||
pbexamplepb "github.com/grpc-ecosystem/grpc-gateway/examples/proto/examplepb" | ||
pbpathenum "github.com/grpc-ecosystem/grpc-gateway/examples/proto/pathenum" | ||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
) | ||
|
||
// String returns a string representation of "NumericEnum" | ||
func (e ExamplepbNumericEnum) String() string { | ||
return pbexamplepb.NumericEnum_ONE.String() | ||
} | ||
|
||
// UnmarshalJSON does a no-op unmarshal to ExamplepbNumericEnum. | ||
// It just validates that the input is sane. | ||
func (e ExamplepbNumericEnum) UnmarshalJSON(b []byte) error { | ||
return unmarshalJSONEnum(b, pbexamplepb.NumericEnum_value) | ||
} | ||
|
||
// String returns a string representation of "MessagePathEnum" | ||
func (e MessagePathEnumNestedPathEnum) String() string { | ||
return pbpathenum.MessagePathEnum_GHI.String() | ||
} | ||
|
||
// UnmarshalJSON does a no-op unmarshal to MessagePathEnumNestedPathEnum. | ||
// It just validates that the input is sane. | ||
func (e MessagePathEnumNestedPathEnum) UnmarshalJSON(b []byte) error { | ||
return unmarshalJSONEnum(b, pbpathenum.MessagePathEnum_NestedPathEnum_value) | ||
} | ||
|
||
// String returns a string representation of "PathEnum" | ||
func (e PathenumPathEnum) String() string { | ||
return pbpathenum.PathEnum_ABC.String() | ||
} | ||
|
||
// UnmarshalJSON does a no-op unmarshal to PathenumPathEnum. | ||
// It just validates that the input is sane. | ||
func (e PathenumPathEnum) UnmarshalJSON(b []byte) error { | ||
return unmarshalJSONEnum(b, pbpathenum.PathEnum_value) | ||
} | ||
|
||
func unmarshalJSONEnum(b []byte, enumValMap map[string]int32) error { | ||
val := string(b[1 : len(b)-1]) | ||
_, err := runtime.Enum(val, enumValMap) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
examples/clients/abe/message_path_enum_nested_path_enum.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* A Bit of Everything | ||
* | ||
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) | ||
* | ||
* OpenAPI spec version: 1.0 | ||
* Contact: none@example.com | ||
* Generated by: https://github.com/swagger-api/swagger-codegen.git | ||
*/ | ||
|
||
package abe | ||
|
||
type MessagePathEnumNestedPathEnum struct { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* A Bit of Everything | ||
* | ||
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) | ||
* | ||
* OpenAPI spec version: 1.0 | ||
* Contact: none@example.com | ||
* Generated by: https://github.com/swagger-api/swagger-codegen.git | ||
*/ | ||
|
||
package abe | ||
|
||
type PathenumPathEnum struct { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.