diff --git a/Makefile b/Makefile index ff8d1621..6b3bd29c 100644 --- a/Makefile +++ b/Makefile @@ -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)" diff --git a/README.md b/README.md index b3561714..ed1c16e5 100644 --- a/README.md +++ b/README.md @@ -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 | @@ -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 @@ -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 ``` diff --git a/internal/converter/converter.go b/internal/converter/converter.go index 305bcbe3..ecfdaa72 100644 --- a/internal/converter/converter.go +++ b/internal/converter/converter.go @@ -18,7 +18,7 @@ import ( ) const ( - defaultFileExtention = "json" + defaultFileExtension = "json" defaultRefPrefix = "#/definitions/" messageDelimiter = "+" ) @@ -30,7 +30,7 @@ type Converter struct { logger *logrus.Logger refPrefix string requiredFieldOption string - schemaFileExtention string + schemaFileExtension string sourceInfo *sourceCodeInfo messageTargets []string } @@ -52,7 +52,7 @@ func New(logger *logrus.Logger) *Converter { return &Converter{ logger: logger, refPrefix: defaultRefPrefix, - schemaFileExtention: defaultFileExtention, + schemaFileExtension: defaultFileExtension, } } @@ -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] } } } @@ -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()) @@ -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: @@ -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: @@ -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) { @@ -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") } } } @@ -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 @@ -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 { diff --git a/internal/converter/converter_test.go b/internal/converter/converter_test.go index 3d714a11..23433eca 100644 --- a/internal/converter/converter_test.go +++ b/internal/converter/converter_test.go @@ -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{}, diff --git a/internal/converter/testdata/file_options.go b/internal/converter/testdata/file_options.go index 51531b24..47de4448 100644 --- a/internal/converter/testdata/file_options.go +++ b/internal/converter/testdata/file_options.go @@ -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, diff --git a/internal/converter/testdata/option_file_extention.go b/internal/converter/testdata/option_file_extension.go similarity index 85% rename from internal/converter/testdata/option_file_extention.go rename to internal/converter/testdata/option_file_extension.go index 3aafbe4a..e842104d 100644 --- a/internal/converter/testdata/option_file_extention.go +++ b/internal/converter/testdata/option_file_extension.go @@ -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" diff --git a/internal/converter/testdata/proto/OptionFileExtention.proto b/internal/converter/testdata/proto/OptionFileExtension.proto similarity index 69% rename from internal/converter/testdata/proto/OptionFileExtention.proto rename to internal/converter/testdata/proto/OptionFileExtension.proto index 50c669e6..9ed9bc62 100644 --- a/internal/converter/testdata/proto/OptionFileExtention.proto +++ b/internal/converter/testdata/proto/OptionFileExtension.proto @@ -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; diff --git a/internal/protos/options.pb.go b/internal/protos/options.pb.go index b1f2b31d..d8afbb13 100644 --- a/internal/protos/options.pb.go +++ b/internal/protos/options.pb.go @@ -91,8 +91,8 @@ type FileOptions struct { // Files tagged with this will not be processed Ignore bool `protobuf:"varint,1,opt,name=ignore,proto3" json:"ignore,omitempty"` - // Override the default file extention for schemas generated from this file - Extention string `protobuf:"bytes,2,opt,name=extention,proto3" json:"extention,omitempty"` + // Override the default file extension for schemas generated from this file + Extension string `protobuf:"bytes,2,opt,name=extension,proto3" json:"extension,omitempty"` } func (x *FileOptions) Reset() { @@ -134,9 +134,9 @@ func (x *FileOptions) GetIgnore() bool { return false } -func (x *FileOptions) GetExtention() string { +func (x *FileOptions) GetExtension() string { if x != nil { - return x.Extention + return x.Extension } return "" } @@ -276,8 +276,8 @@ var file_options_proto_rawDesc = []byte{ 0x28, 0x08, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x22, 0x43, 0x0a, 0x0b, 0x46, 0x69, 0x6c, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x69, 0x67, 0x6e, - 0x6f, 0x72, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x6f, 0x6e, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x6f, + 0x6f, 0x72, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0xca, 0x01, 0x0a, 0x0e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x12, 0x2e, 0x0a, 0x13, diff --git a/jsonschemas/FileOptions.json b/jsonschemas/FileOptions.json index 418505f7..f2239299 100644 --- a/jsonschemas/FileOptions.json +++ b/jsonschemas/FileOptions.json @@ -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, diff --git a/jsonschemas/OptionFileExtention.jsonschema b/jsonschemas/OptionFileExtension.jsonschema similarity index 88% rename from jsonschemas/OptionFileExtention.jsonschema rename to jsonschemas/OptionFileExtension.jsonschema index a092d483..08ee918b 100644 --- a/jsonschemas/OptionFileExtention.jsonschema +++ b/jsonschemas/OptionFileExtension.jsonschema @@ -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" diff --git a/options.proto b/options.proto index 1a1b3d46..835aaec6 100644 --- a/options.proto +++ b/options.proto @@ -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; }