Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Fixing a spelling mistake (#96)
Browse files Browse the repository at this point in the history
Co-authored-by: Chrusty <>
  • Loading branch information
chrusty authored Oct 7, 2021
1 parent f5cde95 commit 74c8a1d
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ samples: build
@protoc --plugin=bin/protoc-gen-jsonschema --jsonschema_out=jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/Proto2Required.proto || echo "No messages found (Proto2Required.proto)"
@protoc --plugin=bin/protoc-gen-jsonschema --jsonschema_out=jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/Proto2NestedMessage.proto || echo "No messages found (Proto2NestedMessage.proto)"
@protoc --plugin=bin/protoc-gen-jsonschema --jsonschema_out=jsonschemas --proto_path=${PROTO_PATH} ${PROTO_PATH}/GoogleValue.proto || echo "No messages found (GoogleValue.proto)"
@protoc --plugin=bin/protoc-gen-jsonschema --jsonschema_out=jsonschemas -I. --proto_path=${PROTO_PATH} ${PROTO_PATH}/OptionFileExtention.proto || echo "No messages found (OptionFileExtention.proto)"
@protoc --plugin=bin/protoc-gen-jsonschema --jsonschema_out=jsonschemas -I. --proto_path=${PROTO_PATH} ${PROTO_PATH}/OptionFileExtension.proto || echo "No messages found (OptionFileExtension.proto)"
@protoc --plugin=bin/protoc-gen-jsonschema --jsonschema_out=jsonschemas -I. --proto_path=${PROTO_PATH} ${PROTO_PATH}/OptionIgnoredField.proto || echo "No messages found (HiddenFields.proto)"
@protoc --plugin=bin/protoc-gen-jsonschema --jsonschema_out=jsonschemas -I. --proto_path=${PROTO_PATH} ${PROTO_PATH}/OptionIgnoredFile.proto || echo "No messages found (IgnoredFile.proto)"
@protoc --plugin=bin/protoc-gen-jsonschema --jsonschema_out=jsonschemas -I. --proto_path=${PROTO_PATH} ${PROTO_PATH}/OptionIgnoredMessage.proto || echo "No messages found (IgnoredMessage.proto)"
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ The following configuration parameters are supported. They should be added to th
|`disallow_additional_properties`| Disallow additional properties in schema |
|`disallow_bigints_as_strings`| Disallow big integers as strings |
|`enforce_oneof`| Interpret Proto "oneOf" clauses |
|`file_extention`| Specify a custom file extention for generated schemas |
|`file_extension`| Specify a custom file extension for generated schemas |
|`json_fieldnames`| Use JSON field names only |
|`prefix_schema_files_with_package`| Prefix the output filename with package |
|`proto_and_json_fieldnames`| Use proto and JSON field names |
Expand All @@ -102,7 +102,7 @@ These apply to specifically marked fields, giving you more finely-grained contro
These options apply to an entire proto file.

- [ignore](internal/converter/testdata/proto/OptionIgnoredFile.proto): Ignore (skip) a specific file
- [extention](internal/converter/testdata/proto/OptionFileExtention.proto): Specify a custom file-extention for the generated schema for this file
- [extension](internal/converter/testdata/proto/OptionFileExtension.proto): Specify a custom file-extension for the generated schema for this file

### Message Options

Expand Down Expand Up @@ -192,13 +192,13 @@ protoc \
--proto_path=testdata/proto testdata/proto/ArrayOfPrimitives.proto
```

### Custom schema file extention
### Custom schema file extension

The default file extention is `json`. You can override that with the "file_extention" parameter.
The default file extension is `json`. You can override that with the "file_extension" parameter.

```sh
protoc \
--jsonschema_out=file_extention=jsonschema:. \
--jsonschema_out=file_extension=jsonschema:. \
--proto_path=internal/converter/testdata/proto internal/converter/testdata/proto/ArrayOfPrimitives.proto
```

Expand Down
38 changes: 19 additions & 19 deletions internal/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

const (
defaultFileExtention = "json"
defaultFileExtension = "json"
defaultRefPrefix = "#/definitions/"
messageDelimiter = "+"
)
Expand All @@ -30,7 +30,7 @@ type Converter struct {
logger *logrus.Logger
refPrefix string
requiredFieldOption string
schemaFileExtention string
schemaFileExtension string
sourceInfo *sourceCodeInfo
messageTargets []string
}
Expand All @@ -52,7 +52,7 @@ func New(logger *logrus.Logger) *Converter {
return &Converter{
logger: logger,
refPrefix: defaultRefPrefix,
schemaFileExtention: defaultFileExtention,
schemaFileExtension: defaultFileExtension,
}
}

Expand Down Expand Up @@ -109,9 +109,9 @@ func (c *Converter) parseGeneratorParameters(parameters string) {
c.messageTargets = strings.Split(matches[1], messageDelimiter)
}

// Configure custom file extention:
if parameterParts := strings.Split(parameter, "file_extention="); len(parameterParts) == 2 {
c.schemaFileExtention = parameterParts[1]
// Configure custom file extension:
if parameterParts := strings.Split(parameter, "file_extension="); len(parameterParts) == 2 {
c.schemaFileExtension = parameterParts[1]
}
}
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func (c *Converter) convertEnumType(enum *descriptor.EnumDescriptorProto) (jsons
}

// Converts a proto file into a JSON-Schema:
func (c *Converter) convertFile(file *descriptor.FileDescriptorProto, fileExtention string) ([]*plugin.CodeGeneratorResponse_File, error) {
func (c *Converter) convertFile(file *descriptor.FileDescriptorProto, fileExtension string) ([]*plugin.CodeGeneratorResponse_File, error) {

// Input filename:
protoFileName := path.Base(file.GetName())
Expand All @@ -166,7 +166,7 @@ func (c *Converter) convertFile(file *descriptor.FileDescriptorProto, fileExtent
// Generate standalone ENUMs:
if len(file.GetMessageType()) == 0 {
for _, enum := range file.GetEnumType() {
jsonSchemaFileName := c.generateSchemaFilename(file, fileExtention, enum.GetName())
jsonSchemaFileName := c.generateSchemaFilename(file, fileExtension, enum.GetName())
c.logger.WithField("proto_filename", protoFileName).WithField("enum_name", enum.GetName()).WithField("jsonschema_filename", jsonSchemaFileName).Info("Generating JSON-schema for stand-alone ENUM")

// Convert the ENUM:
Expand Down Expand Up @@ -227,7 +227,7 @@ func (c *Converter) convertFile(file *descriptor.FileDescriptorProto, fileExtent
}

// Generate a schema filename:
jsonSchemaFileName := c.generateSchemaFilename(file, fileExtention, msgDesc.GetName())
jsonSchemaFileName := c.generateSchemaFilename(file, fileExtension, msgDesc.GetName())
c.logger.WithField("proto_filename", protoFileName).WithField("msg_name", msgDesc.GetName()).WithField("jsonschema_filename", jsonSchemaFileName).Info("Generating JSON-schema for MESSAGE")

// Marshal the JSON-Schema into JSON:
Expand Down Expand Up @@ -268,8 +268,8 @@ func (c *Converter) convert(request *plugin.CodeGeneratorRequest) (*plugin.CodeG
// Go through the list of proto files provided by protoc:
for _, fileDesc := range request.GetProtoFile() {

// Start with the default / global file extention:
fileExtention := c.schemaFileExtention
// Start with the default / global file extension:
fileExtension := c.schemaFileExtension

// Check for our custom field options:
if opts := fileDesc.GetOptions(); opts != nil && proto.HasExtension(opts, protos.E_FileOptions) {
Expand All @@ -282,10 +282,10 @@ func (c *Converter) convert(request *plugin.CodeGeneratorRequest) (*plugin.CodeG
continue
}

// Allow the file extention option to take precedence:
if fileOptions.GetExtention() != "" {
fileExtention = fileOptions.GetExtention()
c.logger.WithField("file_name", fileDesc.GetName()).WithField("extention", fileExtention).Debug("Using optional extention")
// Allow the file extension option to take precedence:
if fileOptions.GetExtension() != "" {
fileExtension = fileOptions.GetExtension()
c.logger.WithField("file_name", fileDesc.GetName()).WithField("extension", fileExtension).Debug("Using optional extension")
}
}
}
Expand All @@ -312,7 +312,7 @@ func (c *Converter) convert(request *plugin.CodeGeneratorRequest) (*plugin.CodeG
// Generate schemas for this file:
if _, ok := generateTargets[fileDesc.GetName()]; ok {
c.logger.WithField("filename", fileDesc.GetName()).Debug("Converting file")
converted, err := c.convertFile(fileDesc, fileExtention)
converted, err := c.convertFile(fileDesc, fileExtension)
if err != nil {
response.Error = proto.String(fmt.Sprintf("Failed to convert %s: %v", fileDesc.GetName(), err))
return response, err
Expand All @@ -323,11 +323,11 @@ func (c *Converter) convert(request *plugin.CodeGeneratorRequest) (*plugin.CodeG
return response, nil
}

func (c *Converter) generateSchemaFilename(file *descriptor.FileDescriptorProto, fileExtention, protoName string) string {
func (c *Converter) generateSchemaFilename(file *descriptor.FileDescriptorProto, fileExtension, protoName string) string {
if c.Flags.PrefixSchemaFilesWithPackage {
return fmt.Sprintf("%s/%s.%s", file.GetPackage(), protoName, fileExtention)
return fmt.Sprintf("%s/%s.%s", file.GetPackage(), protoName, fileExtension)
}
return fmt.Sprintf("%s.%s", protoName, fileExtention)
return fmt.Sprintf("%s.%s", protoName, fileExtension)
}

func contains(haystack []string, needle string) bool {
Expand Down
10 changes: 5 additions & 5 deletions internal/converter/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,11 @@ func configureSampleProtos() map[string]sampleProto {
ObjectsToValidateFail: []string{testdata.OptionDisallowAdditionalPropertiesFail},
ObjectsToValidatePass: []string{testdata.OptionDisallowAdditionalPropertiesPass},
},
"OptionFileExtention": {
ExpectedJSONSchema: []string{testdata.OptionFileExtention},
ExpectedFileNames: []string{"OptionFileExtention.jsonschema"},
FilesToGenerate: []string{"OptionFileExtention.proto"},
ProtoFileName: "OptionFileExtention.proto",
"OptionFileExtension": {
ExpectedJSONSchema: []string{testdata.OptionFileExtension},
ExpectedFileNames: []string{"OptionFileExtension.jsonschema"},
FilesToGenerate: []string{"OptionFileExtension.proto"},
ProtoFileName: "OptionFileExtension.proto",
},
"OptionIgnoredFile": {
ExpectedJSONSchema: []string{},
Expand Down
4 changes: 2 additions & 2 deletions internal/converter/testdata/file_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const FileOptions = `{
"type": "boolean",
"description": "Files tagged with this will not be processed"
},
"extention": {
"extension": {
"type": "string",
"description": "Override the default file extention for schemas generated from this file"
"description": "Override the default file extension for schemas generated from this file"
}
},
"additionalProperties": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package testdata

const OptionFileExtention = `{
const OptionFileExtension = `{
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/OptionFileExtention",
"$ref": "#/definitions/OptionFileExtension",
"definitions": {
"OptionFileExtention": {
"OptionFileExtension": {
"properties": {
"name2": {
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ syntax = "proto3";
package samples;
import "options.proto";

option (protoc.gen.jsonschema.file_options).extention = "jsonschema";
option (protoc.gen.jsonschema.file_options).extension = "jsonschema";

message OptionFileExtention {
message OptionFileExtension {
string name2 = 1;
string timestamp2 = 2;
int32 id2 = 3;
Expand Down
12 changes: 6 additions & 6 deletions internal/protos/options.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions jsonschemas/FileOptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"type": "boolean",
"description": "Files tagged with this will not be processed"
},
"extention": {
"extension": {
"type": "string",
"description": "Override the default file extention for schemas generated from this file"
"description": "Override the default file extension for schemas generated from this file"
}
},
"additionalProperties": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/OptionFileExtention",
"$ref": "#/definitions/OptionFileExtension",
"definitions": {
"OptionFileExtention": {
"OptionFileExtension": {
"properties": {
"name2": {
"type": "string"
Expand Down
4 changes: 2 additions & 2 deletions options.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ message FileOptions {
// Files tagged with this will not be processed
bool ignore = 1;

// Override the default file extention for schemas generated from this file
string extention = 2;
// Override the default file extension for schemas generated from this file
string extension = 2;
}


Expand Down

0 comments on commit 74c8a1d

Please sign in to comment.