Skip to content

Commit fdb67cd

Browse files
committed
feat: align grammar with OpenAPI specification
Refs OAI/OpenAPI-Specification#4244
1 parent b2fa107 commit fdb67cd

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/path-templating.bnf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ path-segment = 1*( path-literal / template-expression )
44
slash = "/"
55
path-literal = 1*pchar
66
template-expression = "{" template-expression-param-name "}"
7-
template-expression-param-name = 1*pchar
7+
template-expression-param-name = 1*( %x00-79 / %x7C / %x7E-10FFFF ) ; every UTF8 character except { and } (from OpenAPI)
88

99
; Characters definitions (from RFC 3986)
1010
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
1111
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
1212
pct-encoded = "%" HEXDIG HEXDIG
1313
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
1414
/ "*" / "+" / "," / ";" / "="
15+
16+
; Character definitions (from RFC 5234)
1517
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
1618
DIGIT = %x30-39 ; 0-9
1719
HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"

src/path-templating.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ export default function grammar(){
77
// SUMMARY
88
// rules = 13
99
// udts = 0
10-
// opcodes = 62
10+
// opcodes = 65
1111
// --- ABNF original opcodes
12-
// ALT = 6
12+
// ALT = 7
1313
// CAT = 4
1414
// REP = 5
15-
// RNM = 17
15+
// RNM = 16
1616
// TLS = 27
17-
// TBS = 0
18-
// TRG = 3
17+
// TBS = 1
18+
// TRG = 5
1919
// --- SABNF superset opcodes
2020
// UDT = 0
2121
// AND = 0
2222
// NOT = 0
23-
// characters = [33 - 126]
23+
// characters = [0 - 1114111]
2424
// ```
2525
/* OBJECT IDENTIFIER (for internal parser use) */
2626
this.grammarObject = 'grammarObject';
@@ -82,7 +82,10 @@ export default function grammar(){
8282
/* template-expression-param-name */
8383
this.rules[5].opcodes = [];
8484
this.rules[5].opcodes[0] = { type: 3, min: 1, max: Infinity };// REP
85-
this.rules[5].opcodes[1] = { type: 4, index: 6 };// RNM(pchar)
85+
this.rules[5].opcodes[1] = { type: 1, children: [2,3,4] };// ALT
86+
this.rules[5].opcodes[2] = { type: 5, min: 0, max: 121 };// TRG
87+
this.rules[5].opcodes[3] = { type: 6, string: [124] };// TBS
88+
this.rules[5].opcodes[4] = { type: 5, min: 126, max: 1114111 };// TRG
8689

8790
/* pchar */
8891
this.rules[6].opcodes = [];
@@ -155,14 +158,16 @@ export default function grammar(){
155158
str += "slash = \"/\"\n";
156159
str += "path-literal = 1*pchar\n";
157160
str += "template-expression = \"{\" template-expression-param-name \"}\"\n";
158-
str += "template-expression-param-name = 1*pchar\n";
161+
str += "template-expression-param-name = 1*( %x00-79 / %x7C / %x7E-10FFFF ) ; every UTF8 character except { and } (from OpenAPI)\n";
159162
str += "\n";
160163
str += "; Characters definitions (from RFC 3986)\n";
161164
str += "pchar = unreserved / pct-encoded / sub-delims / \":\" / \"@\"\n";
162165
str += "unreserved = ALPHA / DIGIT / \"-\" / \".\" / \"_\" / \"~\"\n";
163166
str += "pct-encoded = \"%\" HEXDIG HEXDIG\n";
164167
str += "sub-delims = \"!\" / \"$\" / \"&\" / \"'\" / \"(\" / \")\"\n";
165168
str += " / \"*\" / \"+\" / \",\" / \";\" / \"=\"\n";
169+
str += "\n";
170+
str += "; Character definitions (from RFC 5234)\n";
166171
str += "ALPHA = %x41-5A / %x61-7A ; A-Z / a-z\n";
167172
str += "DIGIT = %x30-39 ; 0-9\n";
168173
str += "HEXDIG = DIGIT / \"A\" / \"B\" / \"C\" / \"D\" / \"E\" / \"F\"\n";

test/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('parse', function () {
4141
});
4242

4343
context('/{petId}/', function () {
44-
specify.only('should parse and translate', function () {
44+
specify('should parse and translate', function () {
4545
const parseResult = parse('/{petId}/');
4646

4747
const parts = [];

0 commit comments

Comments
 (0)