Merge remote-tracking branch 'origin/master' into erikj/create_room_is_direct

pull/977/head
David Baker 8 years ago
commit ae1c576648

@ -28,4 +28,8 @@ properties:
items: items:
type: string type: string
type: array type: array
contains_url:
type: boolean
description: If ``true``, includes only events with a url key in their content. If
``false``, excludes those events.
type: object type: object

@ -75,6 +75,13 @@ paths:
description: |- description: |-
The maximum number of events to return. Default: 10. The maximum number of events to return. Default: 10.
x-example: "3" x-example: "3"
- in: query
type: string
name: filter
description: |-
A JSON RoomEventFilter to filter returned events with.
x-example: |-
{"contains_url":true}
responses: responses:
200: 200:
description: A list of messages with a new token to request more. description: A list of messages with a new token to request more.

@ -23,6 +23,8 @@
(`#376 <https://github.com/matrix-org/matrix-doc/pull/376>`_). (`#376 <https://github.com/matrix-org/matrix-doc/pull/376>`_).
- Correct inconsistent specification of ``redacted_because`` fields and their - Correct inconsistent specification of ``redacted_because`` fields and their
values (`#378 <https://github.com/matrix-org/matrix-doc/pull/378>`_). values (`#378 <https://github.com/matrix-org/matrix-doc/pull/378>`_).
- Mark required fields in response objects as such
(`#394 <https://github.com/matrix-org/matrix-doc/pull/394>`_).
- Changes to the API which will be backwards-compatible for clients: - Changes to the API which will be backwards-compatible for clients:
@ -37,6 +39,10 @@
(`#380 <https://github.com/matrix-org/matrix-doc/pull/380>`_). (`#380 <https://github.com/matrix-org/matrix-doc/pull/380>`_).
- Add ``is_direct`` flag to ``/createRoom``. - Add ``is_direct`` flag to ``/createRoom``.
(`#389 <https://github.com/matrix-org/matrix-doc/pull/389>`_). (`#389 <https://github.com/matrix-org/matrix-doc/pull/389>`_).
- Add ``contains_url`` option to ``RoomEventFilter``.
(`#390 <https://github.com/matrix-org/matrix-doc/pull/390>`_).
- Add ``filter`` optional query param to ``/messages``
(`#390 <https://github.com/matrix-org/matrix-doc/pull/390>`_).
r0.2.0 r0.2.0
====== ======

@ -27,6 +27,7 @@ import (
"strings" "strings"
"sync" "sync"
"syscall" "syscall"
"text/template"
"time" "time"
"github.com/hashicorp/golang-lru" "github.com/hashicorp/golang-lru"
@ -83,19 +84,15 @@ func accessTokenQuerystring() string {
return fmt.Sprintf("?access_token=%s", *accessToken) return fmt.Sprintf("?access_token=%s", *accessToken)
} }
func gitClone(url string, shared bool) (string, error) { func gitClone(url string, directory string, shared bool) error {
directory := path.Join("/tmp/matrix-doc", strconv.FormatInt(rand.Int63(), 10))
if err := os.MkdirAll(directory, permissionsOwnerFull); err != nil {
return "", fmt.Errorf("error making directory %s: %v", directory, err)
}
args := []string{"clone", url, directory} args := []string{"clone", url, directory}
if shared { if shared {
args = append(args, "--shared") args = append(args, "--shared")
} }
if err := runGitCommand(directory, args); err != nil { if err := runGitCommand(directory, args); err != nil {
return "", err return err
} }
return directory, nil return nil
} }
func gitCheckout(path, sha string) error { func gitCheckout(path, sha string) error {
@ -159,6 +156,16 @@ func generate(dir string) error {
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
return fmt.Errorf("error generating spec: %v\nOutput from gendoc:\n%v", err, b.String()) return fmt.Errorf("error generating spec: %v\nOutput from gendoc:\n%v", err, b.String())
} }
// cheekily dump the swagger docs into the gen directory so they can be
// served by serveSpec
cmd = exec.Command("python", "dump-swagger.py", "gen/api-docs.json")
cmd.Dir = path.Join(dir, "scripts")
cmd.Stderr = &b
if err := cmd.Run(); err != nil {
return fmt.Errorf("error generating api docs: %v\nOutput from dump-swagger:\n%v", err, b.String())
}
return nil return nil
} }
@ -195,8 +202,14 @@ func (s *server) generateAt(sha string) (dst string, err error) {
return return
} }
} }
dst, err = makeTempDir()
if err != nil {
return
}
log.Printf("Generating %s in %s\n", sha, dst)
s.mu.Lock() s.mu.Lock()
dst, err = gitClone(s.matrixDocCloneURL, true) err = gitClone(s.matrixDocCloneURL, dst, true)
s.mu.Unlock() s.mu.Unlock()
if err != nil { if err != nil {
return return
@ -219,7 +232,7 @@ func (s *server) getSHAOf(ref string) (string, error) {
err := cmd.Run() err := cmd.Run()
s.mu.Unlock() s.mu.Unlock()
if err != nil { if err != nil {
return "", fmt.Errorf("error generating spec: %v\nOutput from gendoc:\n%v", err, b.String()) return "", fmt.Errorf("error generating spec: %v\nOutput from git:\n%v", err, b.String())
} }
return strings.TrimSpace(b.String()), nil return strings.TrimSpace(b.String()), nil
} }
@ -396,6 +409,11 @@ func (s *server) serveSpec(w http.ResponseWriter, req *http.Request) {
cache.Add(sha, pathToContent) cache.Add(sha, pathToContent)
} }
if requestedPath == "api-docs.json" {
// allow other swagger UIs access to our swagger
w.Header().Set("Access-Control-Allow-Origin", "*")
}
if b, ok := pathToContent[requestedPath]; ok { if b, ok := pathToContent[requestedPath]; ok {
w.Write(b) w.Write(b)
return return
@ -588,12 +606,6 @@ func (srv *server) makeIndex(w http.ResponseWriter, req *http.Request) {
writeError(w, 500, err) writeError(w, 500, err)
return return
} }
s := "<body><ul>"
for _, pull := range pulls {
s += fmt.Sprintf(`<li>%d: <a href="%s">%s</a>: <a href="%s">%s</a>: <a href="spec/%d/">spec</a> <a href="diff/html/%d/">spec diff</a> <a href="diff/rst/%d/">rst diff</a></li>`,
pull.Number, pull.User.HTMLURL, pull.User.Login, pull.HTMLURL, pull.Title, pull.Number, pull.Number, pull.Number)
}
s += "</ul>"
branches, err := srv.getBranches() branches, err := srv.getBranches()
if err != nil { if err != nil {
@ -601,7 +613,48 @@ func (srv *server) makeIndex(w http.ResponseWriter, req *http.Request) {
return return
} }
s += `<div>View the spec at:<ul>` // write our stuff into a buffer so that we can change our minds
// and write a 500 if it all goes wrong.
var b bytes.Buffer
b.Write([]byte(`
<head>
<script>
function redirectToApiDocs(relativePath) {
var url = new URL(window.location);
url.pathname += relativePath;
var newLoc = "http://matrix.org/docs/api/client-server/?url=" + encodeURIComponent(url);
window.location = newLoc;
}
</script>
</head>
<body><ul>
`))
tmpl, err := template.New("pr entry").Parse(`
<li>{{.Number}}:
<a href="{{.User.HTMLURL}}">{{.User.Login}}</a>:
<a href="{{.HTMLURL}}">{{.Title}}</a>:
<a href="spec/{{.Number}}/">spec</a>
<a href="#" onclick="redirectToApiDocs('spec/{{.Number}}/api-docs.json')">api docs</a>
<a href="diff/html/{{.Number}}/">spec diff</a>
<a href="diff/rst/{{.Number}}/">rst diff</a>
</li>
`)
if err != nil {
log.Fatal(err)
}
for _, pull := range pulls {
err = tmpl.Execute(&b, pull)
if err != nil {
writeError(w, 500, err)
return
}
}
b.Write([]byte(`
</ul>
<div>View the spec at:<ul>
`))
branchNames := []string{} branchNames := []string{}
for _, branch := range branches { for _, branch := range branches {
if strings.HasPrefix(branch, "drafts/") { if strings.HasPrefix(branch, "drafts/") {
@ -611,15 +664,14 @@ func (srv *server) makeIndex(w http.ResponseWriter, req *http.Request) {
branchNames = append(branchNames, "HEAD") branchNames = append(branchNames, "HEAD")
for _, branch := range branchNames { for _, branch := range branchNames {
href := "spec/" + url.QueryEscape(branch) + "/" href := "spec/" + url.QueryEscape(branch) + "/"
s += fmt.Sprintf(`<li><a href="%s">%s</a></li>`, href, branch) fmt.Fprintf(&b, `<li><a href="%s">%s</a></li>`, href, branch)
if *includesDir != "" { if *includesDir != "" {
s += fmt.Sprintf(`<li><a href="%s?matrixdotorgstyle=1">%s, styled like matrix.org</a></li>`, fmt.Fprintf(&b, `<li><a href="%s?matrixdotorgstyle=1">%s, styled like matrix.org</a></li>`,
href, branch) href, branch)
} }
} }
s += "</ul></div></body>" b.Write([]byte("</ul></div></body>"))
b.WriteTo(w)
io.WriteString(w, s)
} }
func ignoreExitCodeOne(err error) error { func ignoreExitCodeOne(err error) error {
@ -655,10 +707,14 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())
masterCloneDir, err := gitClone(matrixDocCloneURL, false) masterCloneDir, err := makeTempDir()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
log.Printf("Creating master clone dir %s\n", masterCloneDir)
if err = gitClone(matrixDocCloneURL, masterCloneDir, false); err != nil {
log.Fatal(err)
}
s := server{matrixDocCloneURL: masterCloneDir} s := server{matrixDocCloneURL: masterCloneDir}
http.HandleFunc("/spec/", forceHTML(s.serveSpec)) http.HandleFunc("/spec/", forceHTML(s.serveSpec))
http.HandleFunc("/diff/rst/", s.serveRSTDiff) http.HandleFunc("/diff/rst/", s.serveRSTDiff)
@ -691,3 +747,11 @@ func initCache() error {
styledSpecCache = c2 styledSpecCache = c2
return err return err
} }
func makeTempDir() (string, error) {
directory := path.Join("/tmp/matrix-doc", strconv.FormatInt(rand.Int63(), 10))
if err := os.MkdirAll(directory, permissionsOwnerFull); err != nil {
return "", fmt.Errorf("error making directory %s: %v", directory, err)
}
return directory, nil
}

@ -1,7 +1,6 @@
--- ---
layout: project layout: project
title: Try Matrix Now! title: Try Matrix Now!
categories: projects client
--- ---
<html> <html>

@ -1,7 +1,6 @@
--- ---
layout: project layout: project
title: Try Matrix Now! title: Try Matrix Now!
categories: projects client
--- ---
<html> <html>

@ -1,7 +1,6 @@
--- ---
layout: project layout: project
title: Try Matrix Now! title: Try Matrix Now!
categories: projects client
--- ---
<html> <html>

@ -1,7 +1,6 @@
--- ---
layout: project layout: project
title: Vector Desktop title: Vector Desktop
categories: projects client
description: Desktop version of Vector description: Desktop version of Vector
author: Steven Hammerton author: Steven Hammerton
maturity: Alpha maturity: Alpha

@ -96,8 +96,7 @@ def inherit_parents(obj):
return result return result
def get_json_schema_object_fields(obj, enforce_title=False, def get_json_schema_object_fields(obj, enforce_title=False):
mark_required=True):
# Algorithm: # Algorithm:
# f.e. property => add field info (if field is object then recurse) # f.e. property => add field info (if field is object then recurse)
if obj.get("type") != "object": if obj.get("type") != "object":
@ -175,8 +174,7 @@ def get_json_schema_object_fields(obj, enforce_title=False,
try: try:
logger.debug("Processing property %s.%s", obj_title, key_name) logger.debug("Processing property %s.%s", obj_title, key_name)
required = key_name in required_keys required = key_name in required_keys
res = process_prop(key_name, props[key_name], required, res = process_prop(key_name, props[key_name], required)
mark_required)
first_table_rows.append(res["row"]) first_table_rows.append(res["row"])
tables.extend(res["tables"]) tables.extend(res["tables"])
@ -196,7 +194,7 @@ def get_json_schema_object_fields(obj, enforce_title=False,
return tables return tables
def process_prop(key_name, prop, required, mark_required): def process_prop(key_name, prop, required):
prop = inherit_parents(prop) prop = inherit_parents(prop)
value_type = None value_type = None
@ -213,7 +211,6 @@ def process_prop(key_name, prop, required, mark_required):
nested_objects = get_json_schema_object_fields( nested_objects = get_json_schema_object_fields(
prop, prop,
enforce_title=True, enforce_title=True,
mark_required=mark_required,
) )
value_type = nested_objects[0]["title"] value_type = nested_objects[0]["title"]
value_id = value_type value_id = value_type
@ -226,7 +223,6 @@ def process_prop(key_name, prop, required, mark_required):
nested_objects = get_json_schema_object_fields( nested_objects = get_json_schema_object_fields(
items, items,
enforce_title=True, enforce_title=True,
mark_required=mark_required,
) )
value_id = nested_objects[0]["title"] value_id = nested_objects[0]["title"]
value_type = "[%s]" % value_id value_type = "[%s]" % value_id
@ -269,7 +265,7 @@ def process_prop(key_name, prop, required, mark_required):
value_type = " or ".join(value_type) value_type = " or ".join(value_type)
if required and mark_required: if required:
desc = "**Required.** " + desc desc = "**Required.** " + desc
return { return {
@ -284,10 +280,9 @@ def process_prop(key_name, prop, required, mark_required):
} }
def get_tables_for_schema(schema, mark_required=True): def get_tables_for_schema(schema):
schema = inherit_parents(schema) schema = inherit_parents(schema)
tables = get_json_schema_object_fields(schema, tables = get_json_schema_object_fields(schema)
mark_required=mark_required)
# the result may contain duplicates, if objects are referred to more than # the result may contain duplicates, if objects are referred to more than
# once. Filter them out. # once. Filter them out.
@ -470,9 +465,7 @@ class MatrixUnits(Units):
elif res_type and Units.prop(good_response, "schema/properties"): elif res_type and Units.prop(good_response, "schema/properties"):
# response is an object: # response is an object:
schema = good_response["schema"] schema = good_response["schema"]
res_tables = get_tables_for_schema(schema, res_tables = get_tables_for_schema(schema)
mark_required=False,
)
endpoint["res_tables"].extend(res_tables) endpoint["res_tables"].extend(res_tables)
elif res_type and Units.prop(good_response, "schema/items"): elif res_type and Units.prop(good_response, "schema/items"):
# response is an array: # response is an array:

Loading…
Cancel
Save