Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
xml-validation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vaclab
xml-validation
Commits
692dd60f
Commit
692dd60f
authored
6 years ago
by
wactbprot
Browse files
Options
Downloads
Patches
Plain Diff
rm is_valid api
parent
4cae0412
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+47
-7
47 additions, 7 deletions
README.md
server.py
+14
-6
14 additions, 6 deletions
server.py
utils.py
+8
-7
8 additions, 7 deletions
utils.py
with
69 additions
and
20 deletions
README.md
+
47
−
7
View file @
692dd60f
...
@@ -38,31 +38,66 @@ xmllint --valid --noout 11044_17_DCC_v1.8.1_Au.xml
...
@@ -38,31 +38,66 @@ xmllint --valid --noout 11044_17_DCC_v1.8.1_Au.xml
## API
## API
### /is_valid endpoint [POST]
### /validate endpoint [POST]
```
```
> curl -X POST -H "Content-Type: text/xml" -d @valid_xml_matches_xsd http://localhost:5005/
is_
valid
> curl -X POST -H "Content-Type: text/xml" -d @valid_xml_matches_xsd http://localhost:5005/valid
ate
> <ok/>
> <ok/>
```
```
```
```
> curl -X POST -H "Content-Type: text/xml" -d @no_valid_xml http://localhost:5005/
is_
valid
> curl -X POST -H "Content-Type: text/xml" -d @no_valid_xml http://localhost:5005/valid
ate
> <error>unvalid xml data</error>
> <error>unvalid xml data</error>
```
```
```
```
> curl -X POST -H "Content-Type: text/xml" -d @valid_xml_but_dont_matches_xsd http://localhost:5005/
is_
valid
> curl -X POST -H "Content-Type: text/xml" -d @valid_xml_but_dont_matches_xsd http://localhost:5005/valid
ate
> <error>
not valid
</error>
> <error>
verbose error message
</error>
```
```
Example:
Example:
```
```
> curl -X POST -H "Content-Type: text/xml" -d @11044_17_DCC_v1.8.1_Au.xml http://localhost:5005/is_valid
> curl -X POST -H "Content-Type: text/xml" -d @11044_17_DCC_v1.8.1_Au_with_error.xml http://localhost:5005/validate
> <ok/>
> <error>failed decoding 'A' with XsdAtomicBuiltin(name='xs:double'):
Reason: could not convert string to float: 'A'
Schema:
<simpleType xmlns="http://www.w3.org/2001/XMLSchema" xmlns:hfp="http://www.w3.org/2001/XMLSchema-hasFacetAndProperty" id="double" name="double">
<annotation>
<appinfo>
<hfp:hasFacet name="pattern" />
<hfp:hasFacet name="enumeration" />
<hfp:hasFacet name="whiteSpace" />
<hfp:hasFacet name="maxInclusive" />
<hfp:hasFacet name="maxExclusive" />
<hfp:hasFacet name="minInclusive" />
<hfp:hasFacet name="minExclusive" />
<hfp:hasProperty name="ordered" value="total" />
<hfp:hasProperty name="bounded" value="true" />
<hfp:hasProperty name="cardinality" value="finite" />
<hfp:hasProperty name="numeric" value="true" />
</appinfo>
<documentation source="http://www.w3.org/TR/xmlschema-2/#double" />
</annotation>
<restriction base="xs:anySimpleType">
<whiteSpace fixed="true" id="double.whiteSpace" value="collapse" />
</restriction>
</simpleType>
Instance:
<ns0:coverageProbability xmlns:ns0="https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/SI">A</ns0:coverageProbability>
Path: /{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC}digitalCalibrationCertificate/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC}measurementResults/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC}influenceConditions/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC}influenceCondition/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC}outcome/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC}data/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC}quantity/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/SI}list/{https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/SI}coverageProbability
</error>
```
```
### /version [GET]
### /version [GET]
Returns the version of the validation server:
Returns the version of the validation server:
...
@@ -71,3 +106,8 @@ Returns the version of the validation server:
...
@@ -71,3 +106,8 @@ Returns the version of the validation server:
> curl http://localhost:5005/version
> curl http://localhost:5005/version
> <version>0.2.0</version>
> <version>0.2.0</version>
```
```
### /update [POST]
Updates the server; used by webhook (no security checks so far).
\ No newline at end of file
This diff is collapsed.
Click to expand it.
server.py
+
14
−
6
View file @
692dd60f
...
@@ -38,19 +38,27 @@ def update_xsd():
...
@@ -38,19 +38,27 @@ def update_xsd():
return
utils
.
xml_response
(
ret
)
return
utils
.
xml_response
(
ret
)
@app.route
(
'
/is_valid
'
,
methods
=
[
'
post
'
])
@app.route
(
'
/is_valid
'
,
methods
=
[
'
post
'
])
def
is_valid
():
def
is_valid
():
app
.
logger
.
debug
(
'
hit is_valid
'
)
xml_str
=
request
.
data
xml_tree
=
utils
.
parse
(
xml_str
)
if
xml_tree
:
xsd_str
=
utils
.
get_xsd
(
config
,
xsd_file_name
,
from_server
=
False
)
ret
=
utils
.
is_valid
(
xml_str
=
xml_str
,
xsd_str
=
xsd_str
)
else
:
ret
=
'
<error>unvalid xml data</error>
'
return
utils
.
xml_response
(
ret
)
@app.route
(
'
/validate
'
,
methods
=
[
'
post
'
])
def
validate
():
app
.
logger
.
debug
(
'
hit validate
'
)
app
.
logger
.
debug
(
'
hit validate
'
)
xml_str
=
request
.
data
xml_str
=
request
.
data
xml_tree
=
utils
.
parse
(
xml_str
)
xml_tree
=
utils
.
parse
(
xml_str
)
if
xml_tree
:
if
xml_tree
:
xsd_str
=
utils
.
get_xsd
(
config
,
xsd_file_name
,
from_server
=
False
)
xsd_str
=
utils
.
get_xsd
(
config
,
xsd_file_name
,
from_server
=
False
)
res
=
utils
.
is_valid
(
xml_str
=
xml_str
,
xsd_str
=
xsd_str
)
ret
=
utils
.
validate
(
xml_str
=
xml_str
,
xsd_str
=
xsd_str
)
if
res
:
ret
=
'
<ok/>
'
else
:
ret
=
'
<error>not valid</error>
'
else
:
else
:
ret
=
'
<error>unvalid xml data</error>
'
ret
=
'
<error>unvalid xml data</error>
'
...
...
This diff is collapsed.
Click to expand it.
utils.py
+
8
−
7
View file @
692dd60f
...
@@ -46,13 +46,14 @@ def parse(xml_str):
...
@@ -46,13 +46,14 @@ def parse(xml_str):
return
tree
return
tree
def
is_
valid
(
xml_str
,
xsd_str
):
def
valid
ate
(
xml_str
,
xsd_str
):
tree
=
parse
(
xml_str
)
tree
=
parse
(
xml_str
)
if
tree
:
schema
=
xmlschema
.
XMLSchema
(
xsd_str
)
schema
=
xmlschema
.
XMLSchema
(
xsd_str
)
try
:
return
schema
.
is_valid
(
tree
)
schema
.
validate
(
tree
)
else
:
return
'
<ok/>
'
return
False
except
xmlschema
.
XMLSchemaValidationError
as
error
:
return
'
<error>{error}</error>
'
.
format
(
error
=
error
)
def
xml_response
(
xml_str
):
def
xml_response
(
xml_str
):
return
Response
(
xml_str
,
content_type
=
'
text/xml; charset=utf-8
'
)
return
Response
(
xml_str
,
content_type
=
'
text/xml; charset=utf-8
'
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment