Skip to content

Commit

Permalink
feat(api-linter) fix api linter errors (#15)
Browse files Browse the repository at this point in the history
To ensure full adherence with the AEPs, fix all AEP-linter errors.

This resolves almost all AEP-linter errors, sans a change to 
introduce a path variable for Update which is being discussed
in aep-dev/aeps#210. 

One other error remains, which has to be do with the 
existence of an APPLY method here: aep-dev/aeps#110.

Proto package generation also now aligns with AEP best practices, and to enable
flexibility is now decoupled from the API name.
  • Loading branch information
toumorokoshi authored Aug 23, 2024
1 parent 86ef13e commit 15b5501
Show file tree
Hide file tree
Showing 17 changed files with 1,195 additions and 999 deletions.
30 changes: 30 additions & 0 deletions DESIGN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Design Notes

## Protobuf

AEP and protobuf best practices forces a particular structure between the following that should align:

- Protobuf directory structure and filenames.
- Package names.
- AEP API name.

Using the example in this directory, a file "example/bookstore/bookstore.yaml" from the resource root:

- aep API name is bookstore.example.com
- com.example.bookstore should be the package name.
- so com/example/bookstore.proto should be the directory name.

Open questions:

- Should the AEPC generation match the protobuf convention? so that openapi json files end up in the same directory as the proto files?
- For the AEP API name - is it more correct to go from broadest domain to most qualified domain (e.g. com.example.bookstore instead of example.bookstore.com)?
- this aligns well with the proto, java, and golang packages. It does not align well with how domain names work.

Thinking about something like the following for `bookstore.example.com`:

```
com/
example/
bookstore.proto
bookstore_openapi.json
```
15 changes: 8 additions & 7 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,26 @@ import (

func NewCommand() *cobra.Command {
var inputFile string
var outputFile string
var outputFilePrefix string

c := &cobra.Command{
Use: "aepc",
Short: "aepc compiles resource representations to full proto rpcs",
Long: "aepc compiles resource representations to full proto rpcs",
Run: func(cmd *cobra.Command, args []string) {
err := ProcessInput(inputFile, outputFile)
err := ProcessInput(inputFile, outputFilePrefix)
if err != nil {
log.Fatal(err)
}
},
}
c.Flags().StringVarP(&inputFile, "input", "i", "", "input files with resource")
c.Flags().StringVarP(&outputFile, "output", "o", "", "output file to use")
c.Flags().StringVarP(&outputFilePrefix, "output", "o", "", "output file to write to. File types will be appended to this prefix)")
return c
}

func ProcessInput(inputFile, outputFile string) error {
func ProcessInput(inputFile, outputFilePrefix string) error {
outputDir := filepath.Dir(outputFilePrefix)
s := &schema.Service{}
input, err := ReadFile(inputFile)
fmt.Printf("input: %s\n", string(input))
Expand All @@ -72,15 +73,15 @@ func ProcessInput(inputFile, outputFile string) error {
if err != nil {
return fmt.Errorf("error parsing service: %w", err)
}
proto, _ := proto.WriteServiceToProto(ps)
protoFile := fmt.Sprintf("%s.proto", outputFile)
proto, _ := proto.WriteServiceToProto(ps, outputDir)
protoFile := fmt.Sprintf("%s.proto", outputFilePrefix)
err = WriteFile(protoFile, proto)
if err != nil {
return fmt.Errorf("error writing file: %w", err)
}
fmt.Printf("output proto file: %s\n", protoFile)
openapi, _ := openapi.WriteServiceToOpenAPI(ps)
openapiFile := fmt.Sprintf("%s.openapi.json", outputFile)
openapiFile := fmt.Sprintf("%s_openapi.json", outputFilePrefix)
err = WriteFile(openapiFile, openapi)
if err != nil {
return fmt.Errorf("error writing file: %w", err)
Expand Down
Loading

0 comments on commit 15b5501

Please sign in to comment.