新增:打包编译功能
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
{% load rest_framework %}
|
||||
{% load static %}
|
||||
<pre class="highlight javascript hide" data-language="javascript"><code>{% code html %}<!-- Load the JavaScript client library -->
|
||||
<script src="{% static 'rest_framework/js/coreapi-0.1.1.js' %}"></script>
|
||||
<script src="{% url 'api-docs:schema-js' %}"></script>{% endcode %}</code></pre>
|
||||
15
backend/templates/rest_framework/docs/langs/javascript.html
Normal file
15
backend/templates/rest_framework/docs/langs/javascript.html
Normal file
@@ -0,0 +1,15 @@
|
||||
{% load rest_framework %}
|
||||
<pre class="highlight javascript hide" data-language="javascript"><code>{% code javascript %}var coreapi = window.coreapi // Loaded by `coreapi.js`
|
||||
var schema = window.schema // Loaded by `schema.js`
|
||||
|
||||
// Initialize a client
|
||||
var client = new coreapi.Client()
|
||||
|
||||
// Interact with the API endpoint
|
||||
var action = [{% if section_key %}"{{ section_key }}", {% endif %}"{{ link_key }}"]
|
||||
{% if link.fields %}var params = {
|
||||
{% for field in link.fields %} {{ field.name }}: ...{% if not loop.last %},{% endif %}
|
||||
{% endfor %}}
|
||||
{% endif %}client.action(schema, action{% if link.fields %}, params{% endif %}).then(function(result) {
|
||||
// Return value is in 'result'
|
||||
}){% endcode %}</code></pre>
|
||||
@@ -0,0 +1,3 @@
|
||||
{% load rest_framework %}
|
||||
<pre class="highlight python hide" data-language="python"><code>{% code bash %}# Install the Python client library
|
||||
$ pip install coreapi{% endcode %}</code></pre>
|
||||
13
backend/templates/rest_framework/docs/langs/python.html
Normal file
13
backend/templates/rest_framework/docs/langs/python.html
Normal file
@@ -0,0 +1,13 @@
|
||||
{% load rest_framework %}
|
||||
<pre class="highlight python hide" data-language="python"><code>{% code python %}import coreapi
|
||||
|
||||
# Initialize a client & load the schema document
|
||||
client = coreapi.Client()
|
||||
schema = client.get("{{ document.url }}"{% if schema_format %}, format="{{ schema_format }}"{% endif %})
|
||||
|
||||
# Interact with the API endpoint
|
||||
action = [{% if section_key %}"{{ section_key }}", {% endif %}"{{ link_key }}"]
|
||||
{% if link.fields %}params = {
|
||||
{% for field in link.fields %} "{{ field.name }}": ...{% if not loop.last %},{% endif %}
|
||||
{% endfor %}}
|
||||
{% endif %}result = client.action(schema, action{% if link.fields %}, params=params{% endif %}){% endcode %}</code></pre>
|
||||
@@ -0,0 +1,3 @@
|
||||
{% load rest_framework %}
|
||||
<pre class="highlight shell hide" data-language="shell"><code>{% code bash %}# Install the command line client
|
||||
$ pip install coreapi-cli{% endcode %}</code></pre>
|
||||
6
backend/templates/rest_framework/docs/langs/shell.html
Normal file
6
backend/templates/rest_framework/docs/langs/shell.html
Normal file
@@ -0,0 +1,6 @@
|
||||
{% load rest_framework %}
|
||||
<pre class="highlight shell hide" data-language="shell"><code>{% code bash %}# Load the schema document
|
||||
$ coreapi get {{ document.url }}{% if schema_format %} --format {{ schema_format }}{% endif %}
|
||||
|
||||
# Interact with the API endpoint
|
||||
$ coreapi action {% if section_key %}{{ section_key }} {% endif %}{{ link_key|cut:"> " }}{% for field in link.fields %} -p {{ field.name }}=...{% endfor %}{% endcode %}</code></pre>
|
||||
Reference in New Issue
Block a user