Skip to content

Commit

Permalink
docgenerator: Added support for integer enums.
Browse files Browse the repository at this point in the history
Previously the docs system assumed all enums would
be strings.
  • Loading branch information
adrianholovaty committed Apr 9, 2024
1 parent 59457f2 commit 4a14b95
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 58 deletions.
6 changes: 6 additions & 0 deletions docgenerator/spec/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,12 @@ class Meta:
def __str__(self):
return self.name

def pretty_name(self):
if self.parent.object_type == JSONObject.OBJECT_TYPE_STRING:
return f'"{self.name}"'
else:
return self.name

class ExampleDocument(models.Model):
name = models.CharField(max_length=300)
slug = models.CharField(max_length=100)
Expand Down
2 changes: 1 addition & 1 deletion docgenerator/spec/templates/json_object_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h2>Allowed values:</h2>
</thead>
{% for enum_value in enum_values %}
<tr>
<td><nobr><b>"{{ enum_value.name }}"</b></nobr></td>
<td><nobr><b>{{ enum_value.pretty_name }}</b></nobr></td>
<td>{{ enum_value.description|safe|linebreaksbr }}</td>
</tr>
{% endfor %}
Expand Down
6 changes: 5 additions & 1 deletion docgenerator/spec/utils/jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ def get_schema_for_db_object(db_object, use_defs=True):
}
return result
elif object_type == JSONObject.OBJECT_TYPE_NUMBER:
return {
result = {
'type': 'integer'
}
enums = JSONObjectEnum.objects.filter(parent=db_object)
if enums:
result['enum'] = [int(e.name) for e in enums]
return result
elif object_type == JSONObject.OBJECT_TYPE_BOOLEAN:
return {
'type': 'boolean'
Expand Down
22 changes: 11 additions & 11 deletions docs/mnx-reference/objects/barline-type/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,57 +67,57 @@ <h2>Allowed values:</h2>
</thead>

<tr>
<td><nobr><b>"dashed"</b></nobr></td>
<td><nobr><b>&quot;dashed&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"dotted"</b></nobr></td>
<td><nobr><b>&quot;dotted&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"heavy"</b></nobr></td>
<td><nobr><b>&quot;heavy&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"heavy-heavy"</b></nobr></td>
<td><nobr><b>&quot;heavy-heavy&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"heavy-light"</b></nobr></td>
<td><nobr><b>&quot;heavy-light&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"light-heavy"</b></nobr></td>
<td><nobr><b>&quot;light-heavy&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"light-light"</b></nobr></td>
<td><nobr><b>&quot;light-light&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"none"</b></nobr></td>
<td><nobr><b>&quot;none&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"regular"</b></nobr></td>
<td><nobr><b>&quot;regular&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"short"</b></nobr></td>
<td><nobr><b>&quot;short&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"tick"</b></nobr></td>
<td><nobr><b>&quot;tick&quot;</b></nobr></td>
<td></td>
</tr>

Expand Down
4 changes: 2 additions & 2 deletions docs/mnx-reference/objects/beam-hook-direction/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ <h2>Allowed values:</h2>
</thead>

<tr>
<td><nobr><b>"left"</b></nobr></td>
<td><nobr><b>&quot;left&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"right"</b></nobr></td>
<td><nobr><b>&quot;right&quot;</b></nobr></td>
<td></td>
</tr>

Expand Down
6 changes: 3 additions & 3 deletions docs/mnx-reference/objects/clef-sign/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ <h2>Allowed values:</h2>
</thead>

<tr>
<td><nobr><b>"C"</b></nobr></td>
<td><nobr><b>&quot;C&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"F"</b></nobr></td>
<td><nobr><b>&quot;F&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"G"</b></nobr></td>
<td><nobr><b>&quot;G&quot;</b></nobr></td>
<td></td>
</tr>

Expand Down
6 changes: 3 additions & 3 deletions docs/mnx-reference/objects/grace-type/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ <h2>Allowed values:</h2>
</thead>

<tr>
<td><nobr><b>"make-time"</b></nobr></td>
<td><nobr><b>&quot;make-time&quot;</b></nobr></td>
<td>The run of grace notes delays the onset of the next non-grace event.</td>
</tr>

<tr>
<td><nobr><b>"steal-following"</b></nobr></td>
<td><nobr><b>&quot;steal-following&quot;</b></nobr></td>
<td>The run of grace notes occupies a time interval starting at the expected onset of the next non-grace event, both delaying its onset and shortening its duration.</td>
</tr>

<tr>
<td><nobr><b>"steal-previous"</b></nobr></td>
<td><nobr><b>&quot;steal-previous&quot;</b></nobr></td>
<td>The run of grace notes occupies a time interval that ends before the expected onset of the next non-grace event, shortening the duration of the preceding non-grace event.</td>
</tr>

Expand Down
4 changes: 2 additions & 2 deletions docs/mnx-reference/objects/jump-type/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ <h2>Allowed values:</h2>
</thead>

<tr>
<td><nobr><b>"dsalfine"</b></nobr></td>
<td><nobr><b>&quot;dsalfine&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"segno"</b></nobr></td>
<td><nobr><b>&quot;segno&quot;</b></nobr></td>
<td></td>
</tr>

Expand Down
34 changes: 17 additions & 17 deletions docs/mnx-reference/objects/note-value-base/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,87 +67,87 @@ <h2>Allowed values:</h2>
</thead>

<tr>
<td><nobr><b>"1024th"</b></nobr></td>
<td><nobr><b>&quot;1024th&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"128th"</b></nobr></td>
<td><nobr><b>&quot;128th&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"16th"</b></nobr></td>
<td><nobr><b>&quot;16th&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"2048th"</b></nobr></td>
<td><nobr><b>&quot;2048th&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"256th"</b></nobr></td>
<td><nobr><b>&quot;256th&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"32nd"</b></nobr></td>
<td><nobr><b>&quot;32nd&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"4096th"</b></nobr></td>
<td><nobr><b>&quot;4096th&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"512th"</b></nobr></td>
<td><nobr><b>&quot;512th&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"64th"</b></nobr></td>
<td><nobr><b>&quot;64th&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"breve"</b></nobr></td>
<td><nobr><b>&quot;breve&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"duplexMaxima"</b></nobr></td>
<td><nobr><b>&quot;duplexMaxima&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"eighth"</b></nobr></td>
<td><nobr><b>&quot;eighth&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"half"</b></nobr></td>
<td><nobr><b>&quot;half&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"longa"</b></nobr></td>
<td><nobr><b>&quot;longa&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"maxima"</b></nobr></td>
<td><nobr><b>&quot;maxima&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"quarter"</b></nobr></td>
<td><nobr><b>&quot;quarter&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"whole"</b></nobr></td>
<td><nobr><b>&quot;whole&quot;</b></nobr></td>
<td></td>
</tr>

Expand Down
4 changes: 2 additions & 2 deletions docs/mnx-reference/objects/slur-side/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ <h2>Allowed values:</h2>
</thead>

<tr>
<td><nobr><b>"down"</b></nobr></td>
<td><nobr><b>&quot;down&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"up"</b></nobr></td>
<td><nobr><b>&quot;up&quot;</b></nobr></td>
<td></td>
</tr>

Expand Down
4 changes: 2 additions & 2 deletions docs/mnx-reference/objects/staff-symbol/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ <h2>Allowed values:</h2>
</thead>

<tr>
<td><nobr><b>"brace"</b></nobr></td>
<td><nobr><b>&quot;brace&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"bracket"</b></nobr></td>
<td><nobr><b>&quot;bracket&quot;</b></nobr></td>
<td></td>
</tr>

Expand Down
4 changes: 2 additions & 2 deletions docs/mnx-reference/objects/stem-direction/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ <h2>Allowed values:</h2>
</thead>

<tr>
<td><nobr><b>"down"</b></nobr></td>
<td><nobr><b>&quot;down&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"up"</b></nobr></td>
<td><nobr><b>&quot;up&quot;</b></nobr></td>
<td></td>
</tr>

Expand Down
14 changes: 7 additions & 7 deletions docs/mnx-reference/objects/step/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,37 +67,37 @@ <h2>Allowed values:</h2>
</thead>

<tr>
<td><nobr><b>"A"</b></nobr></td>
<td><nobr><b>&quot;A&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"B"</b></nobr></td>
<td><nobr><b>&quot;B&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"C"</b></nobr></td>
<td><nobr><b>&quot;C&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"D"</b></nobr></td>
<td><nobr><b>&quot;D&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"E"</b></nobr></td>
<td><nobr><b>&quot;E&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"F"</b></nobr></td>
<td><nobr><b>&quot;F&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"G"</b></nobr></td>
<td><nobr><b>&quot;G&quot;</b></nobr></td>
<td></td>
</tr>

Expand Down
4 changes: 2 additions & 2 deletions docs/mnx-reference/objects/up-or-down/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ <h2>Allowed values:</h2>
</thead>

<tr>
<td><nobr><b>"down"</b></nobr></td>
<td><nobr><b>&quot;down&quot;</b></nobr></td>
<td></td>
</tr>

<tr>
<td><nobr><b>"up"</b></nobr></td>
<td><nobr><b>&quot;up&quot;</b></nobr></td>
<td></td>
</tr>

Expand Down

0 comments on commit 4a14b95

Please sign in to comment.