Skip to content

Commit ff0d19e

Browse files
authored
fix(x-aep-resource): fix patterns regex (#46)
The patterns regex vas previously incorrect (not allowing for underscore ids). A few other patterns did not match correctly, so resolved those as well. Added a script to validate that the regex matches the examples to help serve as an additional verification.
1 parent 2f715e1 commit ff0d19e

8 files changed

Lines changed: 1482 additions & 12 deletions

File tree

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ install:
99
# Run linting with prettier
1010
lint: install
1111
npx prettier --check **/*.md
12+
npm run lint:validate-patterns
1213

13-
# Format files with prettier
14-
format: install
14+
15+
# Fix all files automatically, best effort.
16+
fix: install
1517
npx prettier --write **/*.md

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ Common types used in AEPs
1212
aep.dev has registered the extension ids 1264-1274 with the [global extension registry](https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md). Any extensions added to this project should use these values.
1313

1414
To minimize the need to add new ids to the global registry, additions should try to re-use the existing extensions as much as possible (for example, additional field annotations should be added as fields to `aep.api.field_info`).
15+
16+
### Quick Start
17+
18+
```bash
19+
# lint
20+
make lint
21+
22+
# fix as best as possible
23+
make fix
24+
```

json_schema/extensions/x-aep-resource.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,22 @@ properties:
1919
items:
2020
type: string
2121
# see https://aep.dev/4/#type-name
22-
pattern: "^[a-z0-9][.-a-z0-9/]*[a-z0-9]$"
23-
examples:
24-
- "library.example.com/author"
25-
- "library.example.com/user-profile"
22+
pattern: "^[a-z0-9][a-z0-9.-]*/[a-z0-9][-a-z0-9]*$"
23+
examples:
24+
- "library.example.com/author"
25+
- "library.example.com/user-profile"
2626
patterns:
2727
type: array
2828
description: The resource name patterns that are valid for this resource
2929
items:
3030
type: string
31-
pattern: "^[a-z][a-z0-9-]*/\\{[a-z][a-z0-9-]*\\}(/[a-z][a-z0-9-]*/\\{[a-z][a-z0-9-]*\\})*$"
31+
# see https://aep.dev/4/#annotating-resource-types
32+
# this asserts for a leading collection name and pairs of collection, id segments.
33+
pattern: "^[a-z][a-z0-9-]*(/\\{[a-z][a-z0-9_]*\\}|[a-z][a-z0-9-])*" # WIP
34+
examples:
35+
- "books/{book_id}"
36+
- "authors/{author_id}/books/{book_id}"
37+
- "authors/{author_id}/books/{book_id}"
3238
minItems: 1
3339
singleton:
3440
type: boolean
@@ -43,9 +49,8 @@ properties:
4349
description: >
4450
The type of resource, in the form of `{api name}.{resource singular}`.
4551
For example, `api.examples.com/user`.
46-
pattern:
47-
"^[a-z0-9][.-a-z0-9/]*[a-z0-9]$"
48-
# see https://aep.dev/4/#type-name
52+
# see https://aep.dev/4/#type-name
53+
pattern: "^[a-z0-9][a-z0-9_.]*/[a-z0-9][-a-z0-9]*$"
4954
examples:
5055
- "library.example.com/book"
5156
- "library.example.com/author"

0 commit comments

Comments
 (0)